summaryrefslogtreecommitdiff
path: root/src/node_stat_watcher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_stat_watcher.cc')
-rw-r--r--src/node_stat_watcher.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/node_stat_watcher.cc b/src/node_stat_watcher.cc
index cb48c652c9..9aa0c95059 100644
--- a/src/node_stat_watcher.cc
+++ b/src/node_stat_watcher.cc
@@ -111,9 +111,15 @@ void StatWatcher::Start(const FunctionCallbackInfo<Value>& args) {
const bool persistent = args[1]->BooleanValue();
const uint32_t interval = args[2]->Uint32Value();
- if (!persistent)
+ if (uv_is_active(reinterpret_cast<uv_handle_t*>(wrap->watcher_)))
+ return;
+ // Safe, uv_ref/uv_unref are idempotent.
+ if (persistent)
+ uv_ref(reinterpret_cast<uv_handle_t*>(wrap->watcher_));
+ else
uv_unref(reinterpret_cast<uv_handle_t*>(wrap->watcher_));
uv_fs_poll_start(wrap->watcher_, Callback, *path, interval);
+
wrap->ClearWeak();
}