diff options
author | Andrew Paprocki <andrew@ishiboo.com> | 2013-05-28 13:16:16 -0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2013-05-30 15:57:25 +0200 |
commit | 49e3fcd058524826ecbdf57ae7dcb9edd2551af9 (patch) | |
tree | 911f21dee10da1173ce2345f6114c248ae95b870 /src/node_watchdog.h | |
parent | 7ce5a310612bfcfc153836e718fe3c6309369fb4 (diff) | |
download | node-new-49e3fcd058524826ecbdf57ae7dcb9edd2551af9.tar.gz |
vm: fix race condition in watchdog cleanup
Previous code was calling uv_loop_delete() directly on a running loop,
which led to race condition aborts/segfaults within libuv. This change
changes the watchdog thread to call uv_run() with UV_RUN_ONCE so that
the call exits after either the timer times out or uv_async_send() is
called from the main thread in Watchdog::Destroy(). The timer/async
handles are then closed and uv_run() with UV_RUN_DEFAULT is called so
that libuv has a chance to cleanup before the thread exits. The main
thread meanwhile calls uv_thread_join() and then uv_loop_delete() to
complete the cleanup.
Diffstat (limited to 'src/node_watchdog.h')
-rw-r--r-- | src/node_watchdog.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/node_watchdog.h b/src/node_watchdog.h index 1bb4317e33..92a8081047 100644 --- a/src/node_watchdog.h +++ b/src/node_watchdog.h @@ -38,12 +38,13 @@ class Watchdog { void Destroy(); static void Run(void* arg); + static void Async(uv_async_t* async, int status); static void Timer(uv_timer_t* timer, int status); uv_thread_t thread_; uv_loop_t* loop_; + uv_async_t async_; uv_timer_t timer_; - bool timer_started_; bool thread_created_; bool destroyed_; }; |