Skip to content

Commit

Permalink
Infinite loop stucked after our application running in Docker contain…
Browse files Browse the repository at this point in the history
…er with PID 1 aborted

Our service (running in Docker and PID 1) was crashed with SIGABRT signal. After SIGABRT dropped then unfortunatlly infinite SIGSEGV signals were also started to drop. So the infinite loop stucked since the kill signal doesn't stop the infinite loop when running in Docker container with PID 1. We used the similar solution mentioned this PR: KjellKod#419. We also had to restore the saved signal handlers. Without it infinte SIGSEGV signals were dropped circully and this situation also caused pending when running in Docker container with PID 1.
  • Loading branch information
GergoTot authored Mar 3, 2023
1 parent 4f1224b commit 2f18c5b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/crashhandler_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,16 @@ namespace {
// ALL thanks to this thread at StackOverflow. Pretty much borrowed from:
// Ref: http://stackoverflow.com/questions/77005/how-to-generate-a-stacktrace-when-my-gcc-c-app-crashes
void signalHandler(int signal_number, siginfo_t* /*info*/, void* /*unused_context*/) {


using namespace g3::internal;

// Only one signal will be allowed past this point
if (false == shouldDoExit()) {
while (true) {
while (shouldBlockForFatalHandling()) {
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}

using namespace g3::internal;
{
const auto dump = stackdump();
std::ostringstream fatal_stream;
Expand Down Expand Up @@ -233,7 +234,13 @@ namespace g3 {
// --- If LOG(FATAL) or CHECK(false) the signal_number will be SIGABRT
void exitWithDefaultSignalHandler(const LEVELS& level, g3::SignalType fatal_signal_id) {
const int signal_number = static_cast<int>(fatal_signal_id);
restoreSignalHandler(signal_number);

// Restore all signals to handle by the saved handlers. If handling a signal which causes exiting
// then other signals are handled by the original signal handler.
for (const auto& sig : gSignals) {
restoreSignalHandler(sig.first);
}

std::cerr << "\n\n" << __FUNCTION__ << ":" << __LINE__ << ". Exiting due to " << level.text << ", " << signal_number << " \n\n" << std::flush;


Expand Down

0 comments on commit 2f18c5b

Please sign in to comment.