From cd71fc1545db30ca8589ddf1933167286308ad8f Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Sat, 2 Dec 2017 18:37:56 -0800 Subject: src: make FSEventWrap/StatWatcher::Start more robust PR-URL: https://github.com/nodejs/node/pull/17432 Fixes: https://github.com/nodejs/node/issues/17430 Reviewed-By: James M Snell --- src/node_stat_watcher.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/node_stat_watcher.cc') diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc index cb48c652c97..9aa0c950591 100644 --- a/src/node_stat_watcher.cc +++ b/src/node_stat_watcher.cc @@ -111,9 +111,15 @@ void StatWatcher::Start(const FunctionCallbackInfo& args) { const bool persistent = args[1]->BooleanValue(); const uint32_t interval = args[2]->Uint32Value(); - if (!persistent) + if (uv_is_active(reinterpret_cast(wrap->watcher_))) + return; + // Safe, uv_ref/uv_unref are idempotent. + if (persistent) + uv_ref(reinterpret_cast(wrap->watcher_)); + else uv_unref(reinterpret_cast(wrap->watcher_)); uv_fs_poll_start(wrap->watcher_, Callback, *path, interval); + wrap->ClearWeak(); } -- cgit v1.2.3