Skip to content

Commit

Permalink
watchdog: fix timeout for early polling return
Browse files Browse the repository at this point in the history
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: #622
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Rod Vagg <[email protected]>
  • Loading branch information
saghul authored and rvagg committed Jan 27, 2015
1 parent b5166cb commit b50fea4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/node_watchdog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ void Watchdog::Destroy() {
void Watchdog::Run(void* arg) {
Watchdog* wd = static_cast<Watchdog*>(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_
Expand All @@ -75,11 +76,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());
}

Expand Down

0 comments on commit b50fea4

Please sign in to comment.