From 2761f349ecc480f5bf3ccea07be1242275c8deab 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 b92ea0ac99986c..331712f1c9db71 100644 --- a/src/env.cc +++ b/src/env.cc @@ -593,7 +593,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());