Skip to content

Commit e629366

Browse files
committed
src,test: add regression test for nested Worker termination
This adds a regression test for terminating a Worker inside which another Worker is running. PR-URL: #32623 Refs: #32531 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent f621536 commit e629366

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/env.cc

+2
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,8 @@ void Environment::Exit(int exit_code) {
10141014
}
10151015

10161016
void Environment::stop_sub_worker_contexts() {
1017+
DCHECK_EQ(Isolate::GetCurrent(), isolate());
1018+
10171019
while (!sub_worker_contexts_.empty()) {
10181020
Worker* w = *sub_worker_contexts_.begin();
10191021
remove_sub_worker_context(w);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { Worker } = require('worker_threads');
4+
5+
// Check that a Worker that's running another Worker can be terminated.
6+
7+
const worker = new Worker(`
8+
const { Worker, parentPort } = require('worker_threads');
9+
const worker = new Worker('setInterval(() => {}, 10);', { eval: true });
10+
worker.on('online', () => {
11+
parentPort.postMessage({});
12+
});
13+
`, { eval: true });
14+
15+
worker.on('message', common.mustCall(() => worker.terminate()));

0 commit comments

Comments
 (0)