diff --git a/src/node_platform.cc b/src/node_platform.cc index 632217b088ee52..56529bc3a79c4a 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -462,10 +462,12 @@ void NodePlatform::DrainTasks(Isolate* isolate) { std::shared_ptr per_isolate = ForNodeIsolate(isolate); if (!per_isolate) return; - do { - // Worker tasks aren't associated with an Isolate. - worker_thread_task_runner_->BlockingDrain(); - } while (per_isolate->FlushForegroundTasksInternal()); + // Worker tasks aren't associated with an Isolate. + worker_thread_task_runner_->BlockingDrain(); + // Drain foreground tasks but not worker tasks as this may cause deadlocks + // and v8::Isolate::Dispose will join V8's worker tasks for that isolate. + while (per_isolate->FlushForegroundTasksInternal()) { + } } bool PerIsolatePlatformData::FlushForegroundTasksInternal() {