Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,29 @@ subprocess.stdout.on('data', (data) => {
The `subprocess.stdout` property can be `null` or `undefined`
if the child process could not be successfully spawned.

### `subprocess.timedOut`

<!-- YAML
added: REPLACEME
-->

* {boolean}

The `subprocess.timedOut` property indicates whether the child process
was killed due to the `timeout` option set in [`child_process.spawn()`][],
[`child_process.exec()`][], [`child_process.execFile()`][], or
[`child_process.fork()`][].

```js
const { spawn } = require('node:child_process');

const subprocess = spawn('sleep', ['10'], { timeout: 100 });

subprocess.on('exit', () => {
console.log(subprocess.timedOut); // true
});
```

### `subprocess.unref()`

<!-- YAML
Expand Down
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 @@
}), /ERR_OUT_OF_RANGE/);
}

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

Check failure on line 43 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / test-macOS

--- stderr --- /Users/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43 strictEqual(cp.timedOut, false); ^ ReferenceError: strictEqual is not defined at Object.<anonymous> (/Users/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43:3) at Module._compile (node:internal/modules/cjs/loader:1811:14) at Object..js (node:internal/modules/cjs/loader:1942:10) at Module.load (node:internal/modules/cjs/loader:1532:32) at Module._load (node:internal/modules/cjs/loader:1334:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /Users/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js

Check failure on line 43 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04)

--- stderr --- /home/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43 strictEqual(cp.timedOut, false); ^ ReferenceError: strictEqual is not defined at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43:3) at Module._compile (node:internal/modules/cjs/loader:1811:14) at Object..js (node:internal/modules/cjs/loader:1942:10) at Module.load (node:internal/modules/cjs/loader:1532:32) at Module._load (node:internal/modules/cjs/loader:1334:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /home/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js

Check failure on line 43 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / test-linux (ubuntu-24.04-arm)

--- stderr --- /home/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43 strictEqual(cp.timedOut, false); ^ ReferenceError: strictEqual is not defined at Object.<anonymous> (/home/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43:3) at Module._compile (node:internal/modules/cjs/loader:1811:14) at Object..js (node:internal/modules/cjs/loader:1942:10) at Module.load (node:internal/modules/cjs/loader:1532:32) at Module._load (node:internal/modules/cjs/loader:1334:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /home/runner/work/node/node/node/test/parallel/test-child-process-spawn-timeout-kill-signal.js

Check failure on line 43 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'strictEqual' is not defined

Check failure on line 43 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / x86_64-darwin: with shared libraries

--- stderr --- /Users/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43 strictEqual(cp.timedOut, false); ^ ReferenceError: strictEqual is not defined at Object.<anonymous> (/Users/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43:3) at Module._compile (node:internal/modules/cjs/loader:1811:14) at Object..js (node:internal/modules/cjs/loader:1942:10) at Module.load (node:internal/modules/cjs/loader:1532:32) at Module._load (node:internal/modules/cjs/loader:1334:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /Users/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js

Check failure on line 43 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / x86_64-linux: with shared libraries

--- stderr --- /home/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43 strictEqual(cp.timedOut, false); ^ ReferenceError: strictEqual is not defined at Object.<anonymous> (/home/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43:3) at Module._compile (node:internal/modules/cjs/loader:1811:14) at Object..js (node:internal/modules/cjs/loader:1942:10) at Module.load (node:internal/modules/cjs/loader:1532:32) at Module._load (node:internal/modules/cjs/loader:1334:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js

Check failure on line 43 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / aarch64-linux: with shared libraries

--- stderr --- /home/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43 strictEqual(cp.timedOut, false); ^ ReferenceError: strictEqual is not defined at Object.<anonymous> (/home/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43:3) at Module._compile (node:internal/modules/cjs/loader:1811:14) at Object..js (node:internal/modules/cjs/loader:1942:10) at Module.load (node:internal/modules/cjs/loader:1532:32) at Module._load (node:internal/modules/cjs/loader:1334:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /home/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js

Check failure on line 43 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / aarch64-darwin: with shared libraries

--- stderr --- /Users/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43 strictEqual(cp.timedOut, false); ^ ReferenceError: strictEqual is not defined at Object.<anonymous> (/Users/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js:43:3) at Module._compile (node:internal/modules/cjs/loader:1811:14) at Object..js (node:internal/modules/cjs/loader:1942:10) at Module.load (node:internal/modules/cjs/loader:1532:32) at Module._load (node:internal/modules/cjs/loader:1334:12) at wrapModuleLoad (node:internal/modules/cjs/loader:255:19) at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5) at node:internal/main/run_main_module:33:47 Node.js v26.0.0-pre Command: out/Release/node /Users/runner/work/_temp/node-v26.0.0-nightly2026-03-029e858cba22-slim/test/parallel/test-child-process-spawn-timeout-kill-signal.js
cp.on('exit', mustCall(() => {
strictEqual(cp.timedOut, true);

Check failure on line 45 in test/parallel/test-child-process-spawn-timeout-kill-signal.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

'strictEqual' is not defined
}));
}

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