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

win, watchdog: add flag to mark handler as disabled #10248

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 10 additions & 3 deletions src/node_watchdog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ void SigintWatchdogHelper::HandleSignal(int signum) {
// Windows starts a separate thread for executing the handler, so no extra
// helper thread is required.
BOOL WINAPI SigintWatchdogHelper::WinCtrlCHandlerRoutine(DWORD dwCtrlType) {
if (dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT) {
if (!instance.watchdog_disabled_ &&
(dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT)) {
InformWatchdogsAboutSignal();

// Return true because the signal has been handled.
Expand Down Expand Up @@ -207,7 +208,11 @@ int SigintWatchdogHelper::Start() {

RegisterSignalHandler(SIGINT, HandleSignal);
#else
SetConsoleCtrlHandler(WinCtrlCHandlerRoutine, TRUE);
if (watchdog_disabled_) {
watchdog_disabled_ = false;
} else {
SetConsoleCtrlHandler(WinCtrlCHandlerRoutine, TRUE);
}
#endif

return 0;
Expand Down Expand Up @@ -251,7 +256,7 @@ bool SigintWatchdogHelper::Stop() {

RegisterSignalHandler(SIGINT, SignalExit, true);
#else
SetConsoleCtrlHandler(WinCtrlCHandlerRoutine, FALSE);
watchdog_disabled_ = true;
#endif

had_pending_signal = has_pending_signal_;
Expand Down Expand Up @@ -292,6 +297,8 @@ SigintWatchdogHelper::SigintWatchdogHelper()
has_running_thread_ = false;
stopping_ = false;
CHECK_EQ(0, uv_sem_init(&sem_, 0));
#else
watchdog_disabled_ = false;
#endif
}

Expand Down
1 change: 1 addition & 0 deletions src/node_watchdog.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class SigintWatchdogHelper {
static void* RunSigintWatchdog(void* arg);
static void HandleSignal(int signum);
#else
bool watchdog_disabled_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tbh, I would find this a bit easier to read as watchdog_enabled_ with the logic flipped around

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nicer, but with watchdog_disabled_ it is easier to tell if SigintWatchdogHelper::Start() is called for the first time and we have to register the handler or it is called after ::Stop() and we just have to flip the flag.

static BOOL WINAPI WinCtrlCHandlerRoutine(DWORD dwCtrlType);
#endif
};
Expand Down