Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ function spawn(file, args, options) {
let timeoutId = setTimeout(() => {
if (timeoutId) {
try {
child.timedOut = true;
child.kill(killSignal);
} catch (err) {
child.emit('error', err);
Expand Down
1 change: 1 addition & 0 deletions lib/internal/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ function ChildProcess() {
this.exitCode = null;
this.killed = false;
this.spawnfile = null;
this.timedOut = false;

this._handle = new Process();
this._handle[owner_symbol] = this;
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-child-process-spawn-timeout-kill-signal.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ const aliveForeverFile = 'child-process-stay-alive-forever.js';
}), /ERR_OUT_OF_RANGE/);
}

{
// Verify timedOut flag is set true
const cp = spawn(process.execPath, [fixtures.path(aliveForeverFile)], {
timeout: 6,
});
strictEqual(cp.timedOut, false);
cp.on('exit', mustCall(() => {
strictEqual(cp.timedOut, true);
}));
}

{
// Verify abort signal gets unregistered
const controller = new AbortController();
Expand Down