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

Fix abort() call on appsec helper unload #2900

Merged
merged 1 commit into from
Oct 18, 2024
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
2 changes: 2 additions & 0 deletions appsec/src/helper/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ int appsec_helper_main_impl()

runner->run();

runner->unregister_for_rc_notifications();

finished.store(true, std::memory_order_release);
}};
thread_id = thr.native_handle();
Expand Down
12 changes: 8 additions & 4 deletions appsec/src/helper/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void runner::register_for_rc_notifications()
std::atomic_load(&RUNNER_FOR_NOTIFICATIONS);
if (!runner) {
// NOLINTNEXTLINE(bugprone-lambda-function-name)
SPDLOG_ERROR("No runner to notify of remote config updates");
SPDLOG_WARN("No runner to notify of remote config updates");
ddog_remote_config_path_free(path);
return;
}
Expand All @@ -136,15 +136,19 @@ void runner::register_for_rc_notifications()
});
}

runner::~runner() noexcept
void runner::unregister_for_rc_notifications()
{
SPDLOG_INFO("Unregister runner for RC update callback");
try {
std::shared_ptr<runner> expected = shared_from_this();
std::atomic_compare_exchange_strong(&RUNNER_FOR_NOTIFICATIONS,
&expected, std::shared_ptr<runner>(nullptr));
} catch (...) {
// can only happened if there is no shared_ptr for the runner
// in this case a std::bad_weak_ptr is thrown
// can only happen if there is no shared_ptr for the runner
// in this case a std::bad_weak_ptr is thrown.
// But we only expose runner through a shared pointer, so this would
// require extraordinary actions to destroy the shared pointer but not
// the object.
std::abort();
}
}
Expand Down
4 changes: 3 additions & 1 deletion appsec/src/helper/runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ class runner : public std::enable_shared_from_this<runner> {
runner &operator=(const runner &) = delete;
runner(runner &&) = delete;
runner &operator=(runner &&) = delete;
~runner() noexcept;
~runner() = default;

static void resolve_symbols();

void run() noexcept(false);

void register_for_rc_notifications();

void unregister_for_rc_notifications();

[[nodiscard]] bool interrupted() const
{
return interrupted_.load(std::memory_order_acquire);
Expand Down
Loading