child_process: clear timeout timer on spawn-time error too - #65506
Open
kishore280 wants to merge 3 commits into
Open
child_process: clear timeout timer on spawn-time error too#65506kishore280 wants to merge 3 commits into
kishore280 wants to merge 3 commits into
Conversation
When spawn() fails at the OS level (ENOENT, EACCES, EAGAIN, EMFILE, ENFILE), the resulting ChildProcess only ever emits 'error', never 'exit'. The `timeout` option's cleanup only listened for 'exit', so the timer stayed armed for the full `timeout` duration on any spawn-time failure, holding the event loop open well after the promise/callback had already settled via 'error'. Clear the timer on 'error' as well as 'exit'. Fixes: nodejs#65504 Signed-off-by: kishore280 <maheshwarankishore@gmail.com>
avivkeller
approved these changes
Aug 23, 2026
'close' fires after 'exit' or 'error', so one listener is enough. The old 'error' listener also had a side effect I didn't intend: it quietly stopped Node's 'Unhandled error event' crash for anyone using timeout without their own error handler. Not this fix's job. Signed-off-by: kishore280 <maheshwarankishore@gmail.com>
StefanStojanovic
approved these changes
Aug 24, 2026
Collaborator
aduh95
reviewed
Aug 24, 2026
| @@ -0,0 +1,22 @@ | |||
| 'use strict'; | |||
|
|
|||
| // Measures the child's actual exit time, not just its 'error' event - the outer spawnSync timeout catches a leaked inner timer. | |||
Contributor
There was a problem hiding this comment.
This line has a length of 128. Maximum allowed is 120.
Suggested change
| // Measures the child's actual exit time, not just its 'error' event - the outer spawnSync timeout catches a leaked inner timer. | |
| // Measures the child's actual exit time, not just its 'error' event. | |
| // The outer spawnSync timeout catches a leaked inner timer. |
aduh95
reviewed
Aug 24, 2026
| const bugStallMs = common.platformTimeout(10000); | ||
| const outerTimeoutMs = common.platformTimeout(2000); | ||
|
|
||
| const child = spawnSync(process.execPath, ['-e', ` |
Contributor
There was a problem hiding this comment.
Suggested change
| const child = spawnSync(process.execPath, ['-e', ` | |
| spawnSyncAndExitWithoutError(process.execPath, ['-e', ` |
Signed-off-by: kishore280 <maheshwarankishore@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #65506 +/- ##
==========================================
+ Coverage 90.14% 90.16% +0.02%
==========================================
Files 751 751
Lines 252697 253586 +889
Branches 47557 47772 +215
==========================================
+ Hits 227788 228648 +860
- Misses 16181 16200 +19
- Partials 8728 8738 +10
🚀 New features to boost your workflow:
|
lpinca
approved these changes
Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
timeout's only cleanup waschild.once('exit', clearTimeout). A spawn-time failure (ENOENT etc.) only emitserror, neverexit, so the timer stayed armed for the fulltimeoutduration. Clear it onerrortoo.Checked: doesn't double-fire or race with the timeout's own kill-failure path (
try { child.kill() } catch { child.emit('error') }). Thatemit('error')runs synchronously before the timeout callback's owntimeoutId = null, soclearSpawnTimeoutsees the already-fired timer id and callsclearTimeouton it - a documented no-op. The callback's own null-assignment right after is then redundant but harmless.Fixes: #65504