Skip to content

Commit 055c568

Browse files
addaleaxtargos
authored andcommitted
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 34074aa commit 055c568

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/env.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,8 @@ void Environment::Exit(int exit_code) {
978978
}
979979

980980
void Environment::stop_sub_worker_contexts() {
981+
DCHECK_EQ(Isolate::GetCurrent(), isolate());
982+
981983
while (!sub_worker_contexts_.empty()) {
982984
Worker* w = *sub_worker_contexts_.begin();
983985
remove_sub_worker_context(w);
Lines changed: 15 additions & 0 deletions
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)