-
Notifications
You must be signed in to change notification settings - Fork 857
Dedicated crash handler thread. #21826
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
Changes from 1 commit
c1d34c2
a0e27a6
abc4216
4a0e661
27fb623
1cc8b35
4d39c2c
5b45310
3704b8e
dded8d4
f308917
b5950e6
62e81ff
1f33096
70b04f0
ebf3c43
fb9813c
4b8523d
c09a7c6
c4d6bea
2a2f45e
17d3f81
58cf61d
7ec0d64
065de5e
1da431c
0b9e10c
ff2542f
1c5508d
c5d4a61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -503,6 +503,8 @@ void crashHandlerSignalHandler(int signal, siginfo_t* info, void* ucontext) { | |||||
|
||||||
namespace arangodb { | ||||||
|
||||||
std::atomic<CrashHandler*> CrashHandler::_theCrashHandler; | ||||||
|
||||||
void CrashHandler::triggerCrashHandler() { | ||||||
::crashHandlerState.store(arangodb::CrashHandlerState::CRASH_DETECTED, | ||||||
std::memory_order_release); | ||||||
|
@@ -685,6 +687,13 @@ void CrashHandler::installCrashHandler() { | |||||
|
||||||
CrashHandler::crash(buffer.view()); | ||||||
}); | ||||||
|
||||||
std::atexit([]() { | ||||||
CrashHandler* ch = CrashHandler::_theCrashHandler; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe do a
Suggested change
instead? And similarly in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. As far as I see only |
||||||
if (ch != nullptr) { | ||||||
ch->shutdownCrashHandler(); | ||||||
} | ||||||
}); | ||||||
} | ||||||
|
||||||
/// @brief shuts down the crash handler thread | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,11 +23,12 @@ | |
|
||
#pragma once | ||
|
||
#include <atomic> | ||
#include <string_view> | ||
|
||
namespace arangodb { | ||
|
||
/// @brief States for the crash handler thread coordination | ||
/// @brief States for the crash handler thread coordination. | ||
/// The state of the dedicated crash handler starts with IDLE | ||
/// and moves to CRASH_DETECTED when a crash is detected. When the | ||
/// thread has handled the situation it goes to HANDLING_COMPLETE | ||
|
@@ -42,7 +43,29 @@ enum class CrashHandlerState : int { | |
}; | ||
|
||
class CrashHandler { | ||
std::atomic<bool> _threadRunning{false}; | ||
static std::atomic<CrashHandler*> _theCrashHandler; | ||
Comment on lines
+46
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we omit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would be possible, but I would rather like to leave it as it is. First of all, I think it is easier readable. But more importantly, to do the CAS I have to first create the thread, if I am not mistaken. I would rather not create the thread, then try to compare and swap it into |
||
// This needs to be static for the signal handlers to reach! | ||
A92E
|
||
public: | ||
CrashHandler() { | ||
// starts global background thread if not already done | ||
bool threadRunning = _threadRunning.exchange(true); | ||
if (!threadRunning) { | ||
_theCrashHandler.store(this); | ||
installCrashHandler(); | ||
} | ||
} | ||
|
||
~CrashHandler() { | ||
// joins global background thread if running | ||
bool threadRunning = _threadRunning.exchange(false); | ||
if (threadRunning) { | ||
shutdownCrashHandler(); | ||
} | ||
_theCrashHandler.store(nullptr); | ||
} | ||
|
||
/// @brief log backtrace for current thread to logfile | ||
static void logBacktrace(); | ||
|
||
|
@@ -67,18 +90,19 @@ class CrashHandler { | |
/// @brief disable printing of backtraces | ||
static void disableBacktraces(); | ||
|
||
/// @brief installs the crash handler globally | ||
static void installCrashHandler(); | ||
|
||
/// @brief shuts down the crash handler thread | ||
static void shutdownCrashHandler(); | ||
|
||
/// @brief triggers the crash handler thread to handle a crash | ||
/// @return true if successfully triggered, false if already in progress | ||
static void triggerCrashHandler(); | ||
|
||
/// @brief waits for the crash handler thread to complete its work | ||
static void waitForCrashHandlerCompletion(); | ||
|
||
private: | ||
/// @brief installs the crash handler globally | ||
static void installCrashHandler(); | ||
|
||
/// @brief shuts down the crash handler thread | ||
static void shutdownCrashHandler(); | ||
}; | ||
|
||
} // namespace arangodb |
Uh oh!
There was an error while loading. Please reload this page.