diff --git a/src/node_worker.cc b/src/node_worker.cc index 0e77f449d78aa7..cc9dded4c4df19 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -438,8 +438,6 @@ void Worker::JoinThread() { } Worker::~Worker() { - JoinThread(); - Mutex::ScopedLock lock(mutex_); CHECK(stopped_); @@ -599,6 +597,7 @@ void Worker::StartThread(const FunctionCallbackInfo& args) { [w = std::unique_ptr(w)](Environment* env) { if (w->has_ref_) env->add_refs(-1); + w->JoinThread(); // implicitly delete w }); }, static_cast(w)), 0); diff --git a/test/parallel/test-worker-exit-event-error.js b/test/parallel/test-worker-exit-event-error.js new file mode 100644 index 00000000000000..e2427c7dff726b --- /dev/null +++ b/test/parallel/test-worker-exit-event-error.js @@ -0,0 +1,8 @@ +'use strict'; +const common = require('../common'); +const { Worker } = require('worker_threads'); + +process.on('uncaughtException', common.mustCall()); + +new Worker('', { eval: true }) + .on('exit', common.mustCall(() => { throw new Error('foo'); }));