Skip to content

Conversation

@LucM
Copy link
Contributor

@LucM LucM commented Jan 8, 2026

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

On Node.js v24+ (specifically on macOS), running the CLI in watch mode (e.g., nest start --watch) crashes when a file change is detected.

The error occurs in getAllPid because execSync attempts to spawn a shell (/bin/sh) to run ps. Newer versions of Node.js have stricter handling of file descriptor inheritance during process reloading, causing the shell invocation to fail with EBADF.

Error Log:

Error: spawnSync /bin/sh EBADF
    at Object.spawnSync (node:internal/child_process:1120:20)
    at execSync (node:child_process:991:15)
    at getAllPid (.../lib/utils/tree-kill.js:...)

Issue Number: #3156

What is the new behavior?

The getAllPid function now uses spawnSync directly instead of execSync.

  1. Bypasses Shell: By invoking the ps binary directly (instead of via /bin/sh), we avoid the shell-related file descriptor issues on Node 24.
  2. Explicit Stdio: We explicitly set stdio: 'pipe' to prevent invalid file descriptor inheritance.
  3. Safety: Added a try/catch block. If ps fails for any system-level reason, the CLI now defaults to an empty list (no processes found) rather than crashing the entire watch process.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

  • Tested on macOS with Node.js v24.4.0.
  • Confirmed that nest start --watch correctly restarts the application after file changes without crashing.

Replaces execSync with spawnSync to resolve EBADF error.
@kamilmysliwiec
Copy link
Member

Just tested on Node v24.4.1 and MacOS and I can't reproduce this issue

@LucM
Copy link
Contributor Author

LucM commented Jan 12, 2026

Did you try on a large repository? As it has been mentioned in #3156 and as I found on my side. The error happens only with large repos.

@shnooshnoo
Copy link

shnooshnoo commented Jan 14, 2026

any ETA on when this may be available? Consistently having this issue, any change causes a crash.

upd. tested it locally - this fix solves my issue

@kamilmysliwiec kamilmysliwiec merged commit 3d5dd5c into nestjs:master Jan 15, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants