Skip to content

child_process: add subprocess.timedOut - #66639

Open
marcopiraccini wants to merge 1 commit into
nodejs:mainfrom
marcopiraccini:child-process-timed-out
Open

marcopiraccini wants to merge 1 commit into
nodejs:mainfrom
marcopiraccini:child-process-timed-out

Conversation

@marcopiraccini

@marcopiraccini marcopiraccini commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

When a child process receives its kill signal because timeout expired, callers cannot distinguish that from a signal sent for another reason.

Add subprocess.timedOut for spawn(), exec(), execFile() and fork(), and error.timedOut on errors returned by exec() and execFile(). The flag becomes true only when the timeout successfully sends the signal; it does not guarantee that the process has terminated.

This revisits #51608, which proposed the same property for #51561 but closed without landing. That review requested documentation and noted failing CI. This PR includes API documentation and regression tests for timeout expiry, normal exit, manual termination, non-timeout errors, and descendants keeping stdio open after the child exits.

Fixes: #51561
Refs: #51608

When the timeout option of spawn(), exec(), execFile() or fork()
expires, the child is sent the kill signal and exits with that signal.
Nothing told the caller that the timeout was the reason.

Set subprocess.timedOut to true when the kill signal is sent because of
the timeout, and add the same flag to the error passed to the exec()
and execFile() callback.

Fixes: nodejs#51561
Refs: nodejs#51608
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
@nodejs-github-bot nodejs-github-bot added child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run. labels Oct 10, 2026
@marcopiraccini
marcopiraccini marked this pull request as ready for review October 10, 2026 09:25
@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.43%. Comparing base (ae5a0f4) to head (3989ee0).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66639      +/-   ##
==========================================
- Coverage   92.78%   90.43%   -2.35%     
==========================================
  Files         422      791     +369     
  Lines      193692   276601   +82909     
  Branches    29881    53116   +23235     
==========================================
+ Hits       179718   250148   +70430     
- Misses      13645    16872    +3227     
- Partials      329     9581    +9252     
Files with missing lines Coverage Δ
lib/child_process.js 91.44% <100.00%> (+0.04%) ⬆️
lib/internal/child_process.js 95.13% <100.00%> (+1.68%) ⬆️

... and 500 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

child_process Issues and PRs related to the child_process subsystem. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Know when a process ended due to the child_process.spawn() timeout option

3 participants