diff --git a/src/env.cc b/src/env.cc index 262a1f757f5f87..2e4ef80567c9fe 100644 --- a/src/env.cc +++ b/src/env.cc @@ -398,7 +398,11 @@ void Environment::RegisterHandleCleanups() { void* arg) { handle->data = env; - env->CloseHandle(handle, [](uv_handle_t* handle) {}); + env->CloseHandle(handle, [](uv_handle_t* handle) { +#ifdef DEBUG + memset(handle, 0xab, uv_handle_size(handle->type)); +#endif + }); }; RegisterHandleCleanup( @@ -512,6 +516,7 @@ void Environment::PrintSyncTrace() const { } void Environment::RunCleanup() { + started_cleanup_ = true; TraceEventScope trace_scope(TRACING_CATEGORY_NODE1(environment), "RunCleanup", this); CleanupHandles(); @@ -660,10 +665,13 @@ void Environment::RunAndClearNativeImmediates() { void Environment::ScheduleTimer(int64_t duration_ms) { + if (started_cleanup_) return; uv_timer_start(timer_handle(), RunTimers, duration_ms, 0); } void Environment::ToggleTimerRef(bool ref) { + if (started_cleanup_) return; + if (ref) { uv_ref(reinterpret_cast(timer_handle())); } else { @@ -763,6 +771,8 @@ void Environment::CheckImmediate(uv_check_t* handle) { } void Environment::ToggleImmediateRef(bool ref) { + if (started_cleanup_) return; + if (ref) { // Idle handle is needed only to stop the event loop from blocking in poll. uv_idle_start(immediate_idle_handle(), [](uv_idle_t*){ }); diff --git a/src/env.h b/src/env.h index 597556492b9615..f0c57fe3fb60f8 100644 --- a/src/env.h +++ b/src/env.h @@ -1177,6 +1177,7 @@ class Environment { CleanupHookCallback::Hash, CleanupHookCallback::Equal> cleanup_hooks_; uint64_t cleanup_hook_counter_ = 0; + bool started_cleanup_ = false; static void EnvPromiseHook(v8::PromiseHookType type, v8::Local promise,