Skip to content

Commit

Permalink
src: enter isolate before destructing IsolateData
Browse files Browse the repository at this point in the history
MVP fix for a worker_threads crash where ~WorkerThreadData() ->
~IsolateData() -> Isolate::DetachCppHeap() kicks off a round of
garbage collection that expects an entered isolate.

No test because the crash is not reliably reproducable but the bug
is pretty clearly described in the linked issue and is obvious once
you see it, IMO.

Fixes: #51129
PR-URL: #51138
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
  • Loading branch information
bnoordhuis authored and RafaelGSS committed Jan 2, 2024
1 parent 864ecb0 commit 54dd978
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool*>(data) = true;
Expand Down

0 comments on commit 54dd978

Please sign in to comment.