Skip to content

Commit 7e9d2f8

Browse files
saghulmhdawson
authored andcommitted
watchdog: fix timeout for early polling return
Switch from running the loop with UV_RUN_ONCE to UV_RUN_DEFAULT, because it's possible that the poll returns earlier than expected and thus the timer is not run on a single interation. The loop is not stopped either from the timer callback or from the async handle's. Reviewed-By: Julien Gilli <[email protected]> PR-URL: nodejs/node-v0.x-archive#9410
1 parent a930870 commit 7e9d2f8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/node_watchdog.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,9 @@ void Watchdog::Destroy() {
8787
void Watchdog::Run(void* arg) {
8888
Watchdog* wd = static_cast<Watchdog*>(arg);
8989

90-
// UV_RUN_ONCE so async_ or timer_ wakeup exits uv_run() call.
91-
uv_run(wd->loop_, UV_RUN_ONCE);
90+
// UV_RUN_DEFAULT the loop will be stopped either by the async or the
91+
// timer handle.
92+
uv_run(wd->loop_, UV_RUN_DEFAULT);
9293

9394
// Loop ref count reaches zero when both handles are closed.
9495
// Close the timer handle on this side and let Destroy() close async_
@@ -97,11 +98,14 @@ void Watchdog::Run(void* arg) {
9798

9899

99100
void Watchdog::Async(uv_async_t* async) {
101+
Watchdog* w = ContainerOf(&Watchdog::async_, async);
102+
uv_stop(w->loop_);
100103
}
101104

102105

103106
void Watchdog::Timer(uv_timer_t* timer) {
104107
Watchdog* w = ContainerOf(&Watchdog::timer_, timer);
108+
uv_stop(w->loop_);
105109
V8::TerminateExecution(w->env()->isolate());
106110
}
107111

0 commit comments

Comments
 (0)