diff --git a/src/node_worker.cc b/src/node_worker.cc index 900674bbe4c90e..0affbe7c85a013 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -217,7 +217,13 @@ class WorkerThreadData { CHECK(!loop_init_failed_); bool platform_finished = false; - isolate_data_.reset(); + // https://github.com/nodejs/node/issues/51129 - IsolateData destructor + // can kick off GC before teardown, so ensure the isolate is entered. + { + Locker locker(isolate); + Isolate::Scope isolate_scope(isolate); + isolate_data_.reset(); + } w_->platform_->AddIsolateFinishedCallback(isolate, [](void* data) { *static_cast(data) = true;