diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-05-14 10:12:27 +0300 |
---|---|---|
committer | Michaƫl Zasso <targos@protonmail.com> | 2020-05-16 12:13:30 +0300 |
commit | 48b159562d1dfcf005d3f91b0bfdf10206ce2557 (patch) | |
tree | 5edfc9701f7933c6b89945df309b5c4b6d6c4a2d /src/node_worker.cc | |
parent | fda13d5dcf5c72097125ab40d1095b4fcf8bb68c (diff) |
worker: fix crash when .unref() is called during exit
To be more precise, fix a crash when `worker.unref()` is called
from a message on the Worker that is not emitted before the Worker
thread has stopped.
PR-URL: https://github.com/nodejs/node/pull/33394
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_worker.cc')
-rw-r--r-- | src/node_worker.cc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/node_worker.cc b/src/node_worker.cc index fa778166e93..ee48461136b 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -665,7 +665,7 @@ void Worker::StopThread(const FunctionCallbackInfo<Value>& args) { void Worker::Ref(const FunctionCallbackInfo<Value>& args) { Worker* w; ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); - if (!w->has_ref_) { + if (!w->has_ref_ && !w->thread_joined_) { w->has_ref_ = true; w->env()->add_refs(1); } @@ -674,7 +674,7 @@ void Worker::Ref(const FunctionCallbackInfo<Value>& args) { void Worker::Unref(const FunctionCallbackInfo<Value>& args) { Worker* w; ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); - if (w->has_ref_) { + if (w->has_ref_ && !w->thread_joined_) { w->has_ref_ = false; w->env()->add_refs(-1); } |