Skip to content
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: fix deadlock when calling terminate from exit handler #22073

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,22 +287,21 @@ void Worker::JoinThread() {
}

void Worker::OnThreadStopped() {
Mutex::ScopedLock lock(mutex_);
scheduled_on_thread_stopped_ = false;
{
Mutex::ScopedLock lock(mutex_);
scheduled_on_thread_stopped_ = false;

Debug(this, "Worker %llu thread stopped", thread_id_);
Debug(this, "Worker %llu thread stopped", thread_id_);

{
Mutex::ScopedLock stopped_lock(stopped_mutex_);
CHECK(stopped_);
}
{
Mutex::ScopedLock stopped_lock(stopped_mutex_);
CHECK(stopped_);
}

CHECK_EQ(child_port_, nullptr);
parent_port_ = nullptr;
CHECK_EQ(child_port_, nullptr);
parent_port_ = nullptr;
}

// It's okay to join the thread while holding the mutex because
// OnThreadStopped means it's no longer doing any work that might grab it
// and really just silently exiting.
JoinThread();

{
Expand Down Expand Up @@ -369,6 +368,7 @@ void Worker::StopThread(const FunctionCallbackInfo<Value>& args) {
Worker* w;
ASSIGN_OR_RETURN_UNWRAP(&w, args.This());

Debug(w, "Worker %llu is getting stopped by parent", w->thread_id_);
w->Exit(1);
w->JoinThread();
}
Expand Down