Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.1] Fix race condition on trace_api_plugin shutdown #592

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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