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: do not emit 'exit' events during process.exit() · nodejs/node@aeea7d9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • env.cc
  • test/parallel
    • test-worker-nested-on-process-exit.js
    • test-worker-on-process-exit.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/env.cc‎

Copy file name to clipboardExpand all lines: src/env.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,7 @@ void Environment::Exit(int exit_code) {
968968
isolate(), stack_trace_limit(), StackTrace::kDetailed));
969969
}
970970
if (is_main_thread()) {
971+
set_can_call_into_js(false);
971972
stop_sub_worker_contexts();
972973
DisposePlatform();
973974
exit(exit_code);
Collapse file

‎test/parallel/test-worker-nested-on-process-exit.js‎

Copy file name to clipboard
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const { Worker, workerData } = require('worker_threads');
5+
6+
// Test that 'exit' events for nested Workers are not received when a Worker
7+
// terminates itself through process.exit().
8+
9+
if (workerData === null) {
10+
const nestedWorkerExitCounter = new Int32Array(new SharedArrayBuffer(4));
11+
const w = new Worker(__filename, { workerData: nestedWorkerExitCounter });
12+
w.on('exit', common.mustCall(() => {
13+
assert.strictEqual(nestedWorkerExitCounter[0], 0);
14+
}));
15+
} else {
16+
const nestedWorker = new Worker('setInterval(() => {}, 100)', { eval: true });
17+
// The counter should never be increased here.
18+
nestedWorker.on('exit', () => workerData[0]++);
19+
nestedWorker.on('online', () => process.exit());
20+
}
Collapse file

‎test/parallel/test-worker-on-process-exit.js‎

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
require('../common');
3+
const assert = require('assert');
4+
const { spawnSync } = require('child_process');
5+
const { Worker } = require('worker_threads');
6+
7+
// Test that 'exit' events for Workers are not received when the main thread
8+
// terminates itself through process.exit().
9+
10+
if (process.argv[2] !== 'child') {
11+
const {
12+
stdout, stderr, status
13+
} = spawnSync(process.execPath, [__filename, 'child'], { encoding: 'utf8' });
14+
assert.strictEqual(stderr, '');
15+
assert.strictEqual(stdout, '');
16+
assert.strictEqual(status, 0);
17+
} else {
18+
const nestedWorker = new Worker('setInterval(() => {}, 100)', { eval: true });
19+
// This console.log() should never fire.
20+
nestedWorker.on('exit', () => console.log('exit event received'));
21+
nestedWorker.on('online', () => process.exit());
22+
}

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.