From 1bc4970032e934a54ad5ff952811917fb6569dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Inf=C3=BChr?= Date: Thu, 6 Apr 2023 15:37:12 +0200 Subject: [PATCH 1/3] Do not drain worker tasks on main thread --- src/node_platform.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/node_platform.cc b/src/node_platform.cc index 632217b088ee52..1fb0eab2a869cd 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -462,10 +462,9 @@ 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()); + // 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() { From a475e8873c787d02a9f3a8de82729b832f471b61 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 13 Sep 2024 10:47:44 +0200 Subject: [PATCH 2/3] targos changes --- src/node_platform.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/node_platform.cc b/src/node_platform.cc index 1fb0eab2a869cd..a5e20ce5bd7136 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -464,7 +464,8 @@ void NodePlatform::DrainTasks(Isolate* isolate) { // 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()); + while (per_isolate->FlushForegroundTasksInternal()) { + } } bool PerIsolatePlatformData::FlushForegroundTasksInternal() { From ab23463bf5785ca1323922c3c5e6a2bdf09d21dd Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Tue, 17 Sep 2024 14:07:21 +0200 Subject: [PATCH 3/3] Drain worker tasks only once --- src/node_platform.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/node_platform.cc b/src/node_platform.cc index a5e20ce5bd7136..56529bc3a79c4a 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -462,6 +462,8 @@ void NodePlatform::DrainTasks(Isolate* isolate) { std::shared_ptr per_isolate = ForNodeIsolate(isolate); if (!per_isolate) return; + // 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()) {