From 2e66c50d68e24d83551bf720a4d592a32519c4c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 27 Jan 2015 13:40:40 +0100 Subject: [PATCH] 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. PR-URL: https://github.com/iojs/io.js/pull/622 Reviewed-By: Ben Noordhuis Reviewed-By: Rod Vagg --- src/node_watchdog.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/node_watchdog.cc b/src/node_watchdog.cc index a71a906d708..f1bc672d14b 100644 --- a/src/node_watchdog.cc +++ b/src/node_watchdog.cc @@ -87,8 +87,9 @@ void Watchdog::Destroy() { void Watchdog::Run(void* arg) { Watchdog* wd = static_cast(arg); - // UV_RUN_ONCE so async_ or timer_ wakeup exits uv_run() call. - uv_run(wd->loop_, UV_RUN_ONCE); + // UV_RUN_DEFAULT the loop will be stopped either by the async or the + // timer handle. + uv_run(wd->loop_, UV_RUN_DEFAULT); // Loop ref count reaches zero when both handles are closed. // Close the timer handle on this side and let Destroy() close async_ @@ -97,11 +98,14 @@ void Watchdog::Run(void* arg) { void Watchdog::Async(uv_async_t* async) { + Watchdog* w = ContainerOf(&Watchdog::async_, async); + uv_stop(w->loop_); } void Watchdog::Timer(uv_timer_t* timer) { Watchdog* w = ContainerOf(&Watchdog::timer_, timer); + uv_stop(w->loop_); V8::TerminateExecution(w->env()->isolate()); }