| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5e5aa0b commit 9d1e577
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -665,7 +665,7 @@ void Worker::StopThread(const FunctionCallbackInfo<Value>& args) { | |||
| 665 | 665 | void Worker::Ref(const FunctionCallbackInfo<Value>& args) { | |
| 666 | 666 | Worker* w; | |
| 667 | 667 | ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); | |
| 668 | - if (!w->has_ref_) { | ||
| 668 | + if (!w->has_ref_ && !w->thread_joined_) { | ||
| 669 | 669 | w->has_ref_ = true; | |
| 670 | 670 | w->env()->add_refs(1); | |
| 671 | 671 | } | |
@@ -674,7 +674,7 @@ void Worker::Ref(const FunctionCallbackInfo<Value>& args) { | |||
| 674 | 674 | void Worker::Unref(const FunctionCallbackInfo<Value>& args) { | |
| 675 | 675 | Worker* w; | |
| 676 | 676 | ASSIGN_OR_RETURN_UNWRAP(&w, args.This()); | |
| 677 | - if (w->has_ref_) { | ||
| 677 | + if (w->has_ref_ && !w->thread_joined_) { | ||
| 678 | 678 | w->has_ref_ = false; | |
| 679 | 679 | w->env()->add_refs(-1); | |
| 680 | 680 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const { Worker } = require('worker_threads'); | ||
| 4 | + | ||
| 5 | + // This used to crash because the `.unref()` was unexpected while the Worker | ||
| 6 | + // was exiting. | ||
| 7 | + | ||
| 8 | + const w = new Worker(` | ||
| 9 | + require('worker_threads').parentPort.postMessage({}); | ||
| 10 | + `, { eval: true }); | ||
| 11 | + w.on('message', common.mustCall(() => { | ||
| 12 | + w.unref(); | ||
| 13 | + })); | ||
| 14 | + | ||
| 15 | + // Wait a bit so that the 'message' event is emitted while the Worker exits. | ||
| 16 | + Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 100); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments