From 09c5942bfd0efe92e0a4f6791681be915752283d Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 7 Aug 2020 16:24:36 +0200 Subject: [PATCH] src: spin shutdown loop while immediates are pending This allows using `SetImmediate()` and friends at any point during cleanup. PR-URL: https://github.com/nodejs/node/pull/34662 Fixes: https://github.com/nodejs/node/issues/34657 Refs: https://github.com/nodejs/node/pull/34572 Reviewed-By: Gabriel Schulhof Reviewed-By: James M Snell --- src/env.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/env.cc b/src/env.cc index 62012262aa01fe..eb0fb2992502b9 100644 --- a/src/env.cc +++ b/src/env.cc @@ -634,7 +634,10 @@ void Environment::RunCleanup() { initial_base_object_count_ = 0; CleanupHandles(); - while (!cleanup_hooks_.empty()) { + while (!cleanup_hooks_.empty() || + native_immediates_.size() > 0 || + native_immediates_threadsafe_.size() > 0 || + native_immediates_interrupts_.size() > 0) { // Copy into a vector, since we can't sort an unordered_set in-place. std::vector callbacks( cleanup_hooks_.begin(), cleanup_hooks_.end());