diff --git a/src/env-inl.h b/src/env-inl.h index 002683f89095ca..735dbca6857fa1 100644 --- a/src/env-inl.h +++ b/src/env-inl.h @@ -271,6 +271,16 @@ inline void Environment::CleanupHandles() { delete hc; } + // Closing the destroy_ids_idle_handle_ within the handle cleanup queue + // prevents the async wrap destroy hook from being called. + uv_handle_t* handle = + reinterpret_cast(&destroy_ids_idle_handle_); + handle->data = this; + handle_cleanup_waiting_ = 1; + uv_close(handle, [](uv_handle_t* handle) { + static_cast(handle->data)->FinishHandleCleanup(handle); + }); + while (handle_cleanup_waiting_ != 0) uv_run(event_loop(), UV_RUN_ONCE); }