diff --git a/src/env.cc b/src/env.cc index 501b87201e9ecd..0581d9273d6da7 100644 --- a/src/env.cc +++ b/src/env.cc @@ -604,7 +604,10 @@ void Environment::RunCleanup() { "RunCleanup", this); 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());