-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Comments
bnoordhuis
added
confirmed-bug
Issues with confirmed bugs.
c++
Issues and PRs that require attention from people who are familiar with C++.
worker
Issues and PRs related to Worker support.
labels
Dec 12, 2023
bnoordhuis
added a commit
to bnoordhuis/io.js
that referenced
this issue
Dec 12, 2023
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: nodejs#51129
nodejs-github-bot
pushed a commit
that referenced
this issue
Dec 25, 2023
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 <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
RafaelGSS
pushed a commit
that referenced
this issue
Jan 2, 2024
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 <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
richardlau
pushed a commit
that referenced
this issue
Mar 25, 2024
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 <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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)
WorkerThreadData
constructor creates the isolate andIsolateData
Worker::Run()
enters and exits said isolate (constructs and destructs aLocker
andIsolate::Scope
)Worker::Run()
destructs theWorkerThreadData
instanceWorkerThreadData::~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
Locker
stays around until theWorkerThreadData
destructor finishes.I believe the isolate can (and should) stay scoped to
Worker::Run()
and not leak out. Currently,WorkerThreadData
"loans" the isolate to theWorker
for 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: