Skip to content

child_process: clear timeout timer on spawn-time error too - #65506

Open
kishore280 wants to merge 1 commit into
nodejs:mainfrom
kishore280:fix/spawn-timeout-clear-on-error
Open

child_process: clear timeout timer on spawn-time error too#65506
kishore280 wants to merge 1 commit into
nodejs:mainfrom
kishore280:fix/spawn-timeout-clear-on-error

Conversation

@kishore280

Copy link
Copy Markdown

timeout's only cleanup was child.once('exit', clearTimeout). A spawn-time failure (ENOENT etc.) only emits error, never exit, so the timer stayed armed for the full timeout duration. Clear it on error too.

Checked: doesn't double-fire or race with the timeout's own kill-failure path (try { child.kill() } catch { child.emit('error') }). That emit('error') runs synchronously before the timeout callback's own timeoutId = null, so clearSpawnTimeout sees the already-fired timer id and calls clearTimeout on it - a documented no-op. The callback's own null-assignment right after is then redundant but harmless.

Fixes: #65504

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>
@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 Aug 23, 2026
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.

child_process: timeout option never clears on spawn-time failure (ENOENT etc), hangs process for full timeoutMs

3 participants