Skip to content

Commit ba46374

Browse files
bzozevanlucas
authored andcommitted
watchdog: add flag to mark handler as disabled
Adds flags that marks WinCtrlCHandlerRoutine as disabled instead of removing it. Trying to remove the controller from the controller handle itself leads to deadlock. PR-URL: #10248 Reviewed-By: Anna Henningsen <[email protected]>
1 parent a2ec794 commit ba46374

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/node_watchdog.cc

+10-3
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ void SigintWatchdogHelper::HandleSignal(int signum) {
150150
// Windows starts a separate thread for executing the handler, so no extra
151151
// helper thread is required.
152152
BOOL WINAPI SigintWatchdogHelper::WinCtrlCHandlerRoutine(DWORD dwCtrlType) {
153-
if (dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT) {
153+
if (!instance.watchdog_disabled_ &&
154+
(dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT)) {
154155
InformWatchdogsAboutSignal();
155156

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

208209
RegisterSignalHandler(SIGINT, HandleSignal);
209210
#else
210-
SetConsoleCtrlHandler(WinCtrlCHandlerRoutine, TRUE);
211+
if (watchdog_disabled_) {
212+
watchdog_disabled_ = false;
213+
} else {
214+
SetConsoleCtrlHandler(WinCtrlCHandlerRoutine, TRUE);
215+
}
211216
#endif
212217

213218
return 0;
@@ -251,7 +256,7 @@ bool SigintWatchdogHelper::Stop() {
251256

252257
RegisterSignalHandler(SIGINT, SignalExit, true);
253258
#else
254-
SetConsoleCtrlHandler(WinCtrlCHandlerRoutine, FALSE);
259+
watchdog_disabled_ = true;
255260
#endif
256261

257262
had_pending_signal = has_pending_signal_;
@@ -292,6 +297,8 @@ SigintWatchdogHelper::SigintWatchdogHelper()
292297
has_running_thread_ = false;
293298
stopping_ = false;
294299
CHECK_EQ(0, uv_sem_init(&sem_, 0));
300+
#else
301+
watchdog_disabled_ = false;
295302
#endif
296303
}
297304

src/node_watchdog.h

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class SigintWatchdogHelper {
9191
static void* RunSigintWatchdog(void* arg);
9292
static void HandleSignal(int signum);
9393
#else
94+
bool watchdog_disabled_;
9495
static BOOL WINAPI WinCtrlCHandlerRoutine(DWORD dwCtrlType);
9596
#endif
9697
};

0 commit comments

Comments
 (0)