Skip to content

fix(node): exit when the server fails to listen - #5008

Merged
pi0 merged 1 commit into
mainfrom
fix/node-server-exit
Nov 2, 2026
Merged

pi0 merged 1 commit into
mainfrom
fix/node-server-exit

Conversation

@pi0x

@pi0x pi0x commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #5006

When node-server can't listen (for example EADDRINUSE), srvx logs the error and sets process.exitCode = 1, but doesn't exit. Any other handle (the schedule runner's cron job, or the IPC channel in cluster workers) then keeps a process alive that serves nothing.

The node-server and node-cluster entries now observe server.ready() and exit with code 1 when listening fails. In cluster mode every worker exits, so the primary exits with 1 too. Only non-silent workers log the error, so it isn't printed once per worker.

Tests:

  • New testListenError helper. It holds a port and spawns the built output without TEST/CI, so the schedule runner starts. It expects exit code 1 and EADDRINUSE in the output. Runs for node-server and node-cluster. Both tests failed before the fix (they hit the timeout).
  • The flaky readiness check from the issue: spawned servers in node.test.ts, bun.test.ts, deno-server.test.ts and _close-hook.ts are now polled with fetch instead of waitForPort, which binds the port itself and could race the server's listen(). The new helper also fails fast if the child exits.

🤖 Generated with AI assistant

@pi0x
pi0x requested a review from pi0 as a code owner November 2, 2026 17:52
@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Nov 2, 2026 5:58pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Findings

Actionable comments posted: 2

Caution

Review failed

The pull request is closed.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7d73ef96-fc2d-46d2-8f87-7bb893e89d53
Commits

Reviewing files that changed from the base of the PR and between 2b4d4ce and 168bcfa.

Files selected for processing: 6
  • src/presets/node/runtime/node-cluster.ts
  • src/presets/node/runtime/node-server.ts
  • test/presets/_close-hook.ts
  • test/presets/_listen-error.ts
  • test/presets/_wait-for-server.ts
  • test/presets/node.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Walkthrough

The Node server and cluster runtimes now handle rejected startup readiness promises. Tests add listen-failure coverage and replace port polling with HTTP readiness polling that checks the child process.

Changes: Node startup handling

Layer / File(s) Summary
Handle startup readiness failures
src/presets/node/runtime/node-server.ts, src/presets/node/runtime/node-cluster.ts
The Node server logs readiness errors and exits with status 1. The cluster runtime logs errors unless the worker is silent, then exits with status 1.
Poll server URLs for readiness
test/presets/_wait-for-server.ts, test/presets/_close-hook.ts, test/presets/node.test.ts
The new helper polls a server URL, checks for child-process exit, and times out if the server does not respond. The close-hook and Node preset tests use it instead of port polling.
Test listen failures
test/presets/_listen-error.ts, test/presets/node.test.ts
A new helper checks that a server started on an occupied port exits with status 1 and reports EADDRINUSE. Node server and cluster tests use the helper; the cluster test is skipped on Bun.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • nitrojs/nitro#4724: Both PRs change the Node cluster runtime and overlap in the primary exit-code behavior and Node preset tests.

Suggested labels: v3

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@5008

commit: 168bcfa

srvx only sets process.exitCode on listen errors, so other handles (scheduled tasks, the cluster IPC channel) kept the process alive without serving. Also poll spawned test servers with fetch instead of binding the port.

Resolves #5006
@pi0x
pi0x force-pushed the fix/node-server-exit branch from 168bcfa to d58e48b Compare November 2, 2026 17:57
@pi0
pi0 merged commit 81dd71e into main Nov 2, 2026
13 checks passed
@pi0
pi0 deleted the fix/node-server-exit branch November 2, 2026 17:58

This branch was successfully deployed

1 active deployment
Preview — d58e48b9 Deployed Nov 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

node-server keeps running without listening when the port is in use

2 participants