worker_threads: race and crash on worker exit #51129
Labels
c++
Issues and PRs that require attention from people who are familiar with C++.
confirmed-bug
Issues with confirmed bugs.
worker
Issues and PRs related to Worker support.
Reported with v20.9.0 but also present in ToT. Backtrace is from a debug build.
The race condition is difficult to trigger but the problem is obvious once you see it. The order of events in src/node_worker.cc is as follows:
Worker::Run()createsWorkerThreadData data(this)WorkerThreadDataconstructor creates the isolate andIsolateDataWorker::Run()enters and exits said isolate (constructs and destructs aLockerandIsolate::Scope)Worker::Run()destructs theWorkerThreadDatainstanceWorkerThreadData::~WorkerThreadData()callsIsolateData::~IsolateData()IsolateData::~IsolateData()callsIsolate::DetachCppHeap()Isolate::DetachCppHeap()runs GCGlobalHandles::InvokeFirstPassWeakCallbacks()callsIsolate::GetCurrent()but we've no longer entered the isolate (from step 3) and so it blows up violentlyThe solution IMO is to refactor so that the
Lockerstays around until theWorkerThreadDatadestructor finishes.I believe the isolate can (and should) stay scoped to
Worker::Run()and not leak out. Currently,WorkerThreadData"loans" the isolate to theWorkerfor no good reason I can see.I can submit a patch but I'd like consensus on what approach to take before I start writing/refactoring/deleting code.
The text was updated successfully, but these errors were encountered: