-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: correct (de)initialization order #22773
Conversation
- Initialize `thread_exit_async_` only once the thread has been started. This is done since it is only triggered from the thread when it is exiting. - Move the final `uv_run` to the `Worker` destructor. This makes sure that it is always run, regardless of whether the thread is actually started or not. - Always dispose the `Isolate` before cleaning up the libuv event loop. This now matches the reverse order of initialization. Fixes: nodejs#22736
@@ -361,10 +361,19 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) { | |||
|
|||
w->env()->add_sub_worker_context(w); | |||
w->stopped_ = false; | |||
w->thread_joined_ = false; | |||
|
|||
w->thread_exit_async_.reset(new uv_async_t); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: why is this before the uv_thread_create
? Maybe it's just a non intuitive name OnThreadStopped
?
AFAICT uv_async_send(thread_exit_async_.get())
can only run iff the thread was created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: why is this before the
uv_thread_create
?
Switching these would create a race condition – the worker thread might finish (and try to call uv_async_send()
on this) before we have initialized the async
Maybe it's just a non intuitive name
OnThreadStopped
?
Can you expand on this? It’s an event handler that’s called when the worker thread finishes.
AFAICT
uv_async_send(thread_exit_async_.get())
can only run iff the thread was created.
That is correct, yes.
New CI attempt: https://ci.nodejs.org/job/node-test-pull-request/17167/ |
Landed in df7ebfa |
- Initialize `thread_exit_async_` only once the thread has been started. This is done since it is only triggered from the thread when it is exiting. - Move the final `uv_run` to the `Worker` destructor. This makes sure that it is always run, regardless of whether the thread is actually started or not. - Always dispose the `Isolate` before cleaning up the libuv event loop. This now matches the reverse order of initialization. Fixes: #22736 PR-URL: #22773 Reviewed-By: James M Snell <[email protected]>
- Initialize `thread_exit_async_` only once the thread has been started. This is done since it is only triggered from the thread when it is exiting. - Move the final `uv_run` to the `Worker` destructor. This makes sure that it is always run, regardless of whether the thread is actually started or not. - Always dispose the `Isolate` before cleaning up the libuv event loop. This now matches the reverse order of initialization. Fixes: #22736 PR-URL: #22773 Reviewed-By: James M Snell <[email protected]>
- Initialize `thread_exit_async_` only once the thread has been started. This is done since it is only triggered from the thread when it is exiting. - Move the final `uv_run` to the `Worker` destructor. This makes sure that it is always run, regardless of whether the thread is actually started or not. - Always dispose the `Isolate` before cleaning up the libuv event loop. This now matches the reverse order of initialization. Fixes: #22736 PR-URL: #22773 Reviewed-By: James M Snell <[email protected]>
- Initialize `thread_exit_async_` only once the thread has been started. This is done since it is only triggered from the thread when it is exiting. - Move the final `uv_run` to the `Worker` destructor. This makes sure that it is always run, regardless of whether the thread is actually started or not. - Always dispose the `Isolate` before cleaning up the libuv event loop. This now matches the reverse order of initialization. Fixes: #22736 PR-URL: #22773 Reviewed-By: James M Snell <[email protected]>
thread_exit_async_
only once the thread has beenstarted. This is done since it is only triggered from the
thread when it is exiting.
uv_run
to theWorker
destructor.This makes sure that it is always run, regardless of whether
the thread is actually started or not.
Isolate
before cleaning up the libuv eventloop. This now matches the reverse order of initialization.
Fixes: #22736
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes/cc @nodejs/workers