Skip to content

Commit

Permalink
Fix SIGTERM behavior that causes systemd control of etserver to timeout.
Browse files Browse the repository at this point in the history
From various user reports, `systemctl stop et` hangs and times out
requiring a SIGKILL signal. This does not happen on MacOS which is still
confusing me.  Anyway, in addition to adding the hook to kill
sentry/telemetry on SIGTERM, we need to exit as well.

Fixes #546
  • Loading branch information
James Short committed Dec 16, 2022
1 parent 10dd371 commit 60396d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
11 changes: 9 additions & 2 deletions src/base/Headers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,16 @@ inline void HandleTerminate() {
}

inline void InterruptSignalHandler(int signum) {
STERROR << "Got interrupt";
CLOG(INFO, "stdout") << endl
<< "Got interrupt (perhaps ctrl+c?). Exiting." << endl;
<< "Got interrupt (perhaps ctrl+c?): " << signum
<< ". Exiting." << endl;
::exit(signum);
}

inline void TerminateSignalHandler(int signum) {
CLOG(INFO, "stdout") << endl
<< "Got terminate signal: " << signum << ". Exiting."
<< endl;
::exit(signum);
}

Expand Down
20 changes: 14 additions & 6 deletions src/terminal/TelemetryService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ TelemetryService::TelemetryService(const bool _allow,
}

#ifdef USE_SENTRY
cerr << "Setting up and starting sentry" << endl;
sentry_options_t* options = sentry_options_new();
logHttpClient->set_compress(true);

Expand Down Expand Up @@ -170,9 +171,6 @@ TelemetryService::TelemetryService(const bool _allow,
#ifdef SIGSEGV
SIGSEGV,
#endif
#ifdef SIGTERM
SIGTERM,
#endif
#ifdef SIGKILL
SIGKILL,
#endif
Expand All @@ -181,14 +179,24 @@ TelemetryService::TelemetryService(const bool _allow,
signal(it, sentryShutdownHandler);
}

#ifdef SIGTERM
auto terminateShutdownHandler = [](int i) {
// In addition to exiting like the default SIGTERM handler would do,
// let's shutdown sentry telemetry
shutdownTelemetry();
et::TerminateSignalHandler(i);
};
signal(SIGTERM, terminateShutdownHandler);
#endif
#ifdef SIGINT
signal(SIGINT, [](int i) {
auto interruptShutdownHandler = [](int i) {
shutdownTelemetry();
// Normally this is installed in TerminalServerMain, TerminalClientMain,
// Normally this is configured in TerminalServerMain, TerminalClientMain,
// and TerminalMain, but we need to forward the call since Sentry
// overrides it. This is important to handle SIGINT from Ctrl-C.
et::InterruptSignalHandler(i);
});
};
signal(SIGINT, interruptShutdownHandler);
#endif
#endif
atexit([] { shutdownTelemetry(); });
Expand Down

0 comments on commit 60396d4

Please sign in to comment.