Skip to content

Commit

Permalink
GH-590 Fix race condition on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
heifner committed Jul 2, 2022
1 parent 8ecae67 commit 4e38f24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ namespace eosio::trace_api {
std::optional<uint32_t> _last_compressed_slice;
const size_t _compression_seek_point_stride;

std::atomic<uint32_t> _best_known_lib{0};
std::mutex _maintenance_mtx;
std::condition_variable _maintenance_condition;
std::thread _maintenance_thread;
std::atomic_bool _maintenance_shutdown{false};
bool _maintenance_shutdown{false};
uint32_t _best_known_lib{0};
};

/**
Expand Down
11 changes: 9 additions & 2 deletions plugins/trace_api_plugin/store_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,10 @@ namespace eosio::trace_api {
}

void slice_directory::set_lib(uint32_t lib) {
_best_known_lib = lib;
{
std::scoped_lock lock(_maintenance_mtx);
_best_known_lib = lib;
}
_maintenance_condition.notify_one();
}

Expand All @@ -306,6 +309,7 @@ namespace eosio::trace_api {

uint32_t best_known_lib = _best_known_lib;
bool shutdown = _maintenance_shutdown;
lock.unlock();

log(std::string("Waking up to handle lib: ") + std::to_string(best_known_lib));

Expand All @@ -324,7 +328,10 @@ namespace eosio::trace_api {
}

void slice_directory::stop_maintenance_thread() {
_maintenance_shutdown = true;
{
std::scoped_lock lock(_maintenance_mtx);
_maintenance_shutdown = true;
}
_maintenance_condition.notify_one();
_maintenance_thread.join();
}
Expand Down

0 comments on commit 4e38f24

Please sign in to comment.