GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — worker: fix crash when .unref() is called during exit · nodejs/node@9d1e577

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_worker.cc
  • test/parallel
    • test-worker-unref-from-message-during-exit.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_worker.cc‎

Copy file name to clipboardExpand all lines: src/node_worker.cc
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ void Worker::StopThread(const FunctionCallbackInfo<Value>& args) {
665665
void Worker::Ref(const FunctionCallbackInfo<Value>& args) {
666666
Worker* w;
667667
ASSIGN_OR_RETURN_UNWRAP(&w, args.This());
668-
if (!w->has_ref_) {
668+
if (!w->has_ref_ && !w->thread_joined_) {
669669
w->has_ref_ = true;
670670
w->env()->add_refs(1);
671671
}
@@ -674,7 +674,7 @@ void Worker::Ref(const FunctionCallbackInfo<Value>& args) {
674674
void Worker::Unref(const FunctionCallbackInfo<Value>& args) {
675675
Worker* w;
676676
ASSIGN_OR_RETURN_UNWRAP(&w, args.This());
677-
if (w->has_ref_) {
677+
if (w->has_ref_ && !w->thread_joined_) {
678678
w->has_ref_ = false;
679679
w->env()->add_refs(-1);
680680
}
Collapse file

‎test/parallel/test-worker-unref-from-message-during-exit.js‎

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.