Skip to content

Commit

Permalink
Merge pull request #2900 from DataDog/glopes/abort-on-shutdown
Browse files Browse the repository at this point in the history
Fix abort() call on appsec helper unload
  • Loading branch information
cataphract authored Oct 18, 2024
2 parents 8f7175e + aec4aed commit 16b0255
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
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

0 comments on commit 16b0255

Please sign in to comment.