Skip to content

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

Description

@kishore280

Version

v24.5.0

Platform

Microsoft Windows NT 10.0.26200.0 x64

Subsystem

child_process

What steps will reproduce the bug?

const {spawn} = require('child_process');
const start = Date.now();
const child = spawn('node', ['--version'], {cwd: 'Z:\\nope', timeout: 5000});
child.on('error', e => console.log('error', Date.now() - start, e.code));
process.on('exit', () => console.log('exiting', Date.now() - start));

How often does it reproduce? Is there a required condition?

Always, with timeout set and a spawn that fails at the OS level (ENOENT here).

What is the expected behavior? Why is that the expected behavior?

Process exits within a few ms of error.

What do you see instead?

error 12 ENOENT
exiting 5026

Hangs until timeout elapses.

Additional information

timeout's only cleanup is child.once('exit', clearTimeout). On a spawn-time failure onexit gets exitCode < 0 and emits error, not exit — so the timer never clears. unref() doesn't help either.

No existing issue found for this exact case (#43704, #51561 are different). Fix: clear the timer on error too, or use close instead of exit. Can PR once there's a preferred direction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions