fix runaway thread
All checks were successful
BlockStorage/repertory_linux_builds/pipeline/head This commit looks good
BlockStorage/repertory_osx_builds/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-02-03 10:41:38 -06:00
parent 99533a9687
commit a024f81e5d
2 changed files with 59 additions and 49 deletions

View File

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
#
NUM_JOBS=${MY_NUM_JOBS} NUM_JOBS=${MY_NUM_JOBS}
if [[ -z "${NUM_JOBS}" ]]; then if [[ -z "${NUM_JOBS}" ]]; then
NUM_JOBS=$(getconf _NPROCESSORS_ONLN 2> /dev/null || getconf NPROCESSORS_ONLN 2> /dev/null || echo 1) NUM_JOBS=$(getconf _NPROCESSORS_ONLN 2> /dev/null || getconf NPROCESSORS_ONLN 2> /dev/null || echo 1)

View File

@ -1037,8 +1037,13 @@ void file_manager::upload_handler() {
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__); constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
while (not stop_requested_) { while (not stop_requested_) {
auto should_wait{true};
unique_mutex_lock upload_lock(upload_mtx_); unique_mutex_lock upload_lock(upload_mtx_);
if (not stop_requested_) { if (stop_requested_) {
upload_notify_.notify_all();
continue;
}
if (upload_lookup_.size() < config_.get_max_upload_count()) { if (upload_lookup_.size() < config_.get_max_upload_count()) {
auto result = db::db_select{*db_.get(), upload_table} auto result = db::db_select{*db_.get(), upload_table}
.order_by("api_path", true) .order_by("api_path", true)
@ -1047,8 +1052,7 @@ void file_manager::upload_handler() {
try { try {
std::optional<db::db_select::row> row; std::optional<db::db_select::row> row;
if (result.get_row(row) && row.has_value()) { if (result.get_row(row) && row.has_value()) {
auto api_path = auto api_path = row->get_column("api_path").get_value<std::string>();
row->get_column("api_path").get_value<std::string>();
auto source_path = auto source_path =
row->get_column("source_path").get_value<std::string>(); row->get_column("source_path").get_value<std::string>();
@ -1056,12 +1060,16 @@ void file_manager::upload_handler() {
auto res = provider_.get_filesystem_item(api_path, false, fsi); auto res = provider_.get_filesystem_item(api_path, false, fsi);
switch (res) { switch (res) {
case api_error::item_not_found: { case api_error::item_not_found: {
event_system::instance().raise<file_upload_not_found>( should_wait = false;
api_path, source_path); //
event_system::instance().raise<file_upload_not_found>(api_path,
source_path);
remove_upload(api_path, true); remove_upload(api_path, true);
} break; } break;
case api_error::success: { case api_error::success: {
should_wait = false;
upload_lookup_[fsi.api_path] = upload_lookup_[fsi.api_path] =
std::make_unique<upload>(fsi, provider_); std::make_unique<upload>(fsi, provider_);
auto del_res = db::db_select{*db_.get(), upload_table} auto del_res = db::db_select{*db_.get(), upload_table}
@ -1083,10 +1091,9 @@ void file_manager::upload_handler() {
} break; } break;
default: { default: {
event_system::instance().raise<file_upload_retry>( event_system::instance().raise<file_upload_retry>(api_path,
api_path, source_path, res); source_path, res);
queue_upload(api_path, source_path, true); queue_upload(api_path, source_path, true);
upload_notify_.wait_for(upload_lock, 5s);
} break; } break;
} }
} }
@ -1094,6 +1101,9 @@ void file_manager::upload_handler() {
utils::error::raise_error(function_name, ex, "query error"); utils::error::raise_error(function_name, ex, "query error");
} }
} }
if (should_wait) {
upload_notify_.wait_for(upload_lock, 5s);
} }
upload_notify_.notify_all(); upload_notify_.notify_all();