Skip to content

fix(node): exit non-zero and log error when standalone port is taken - #18335

Open
lx3133584 wants to merge 2 commits into
withastro:mainfrom
lx3133584:fix/node-standalone-eaddrinuse
Open

lx3133584 wants to merge 2 commits into
withastro:mainfrom
lx3133584:fix/node-standalone-eaddrinuse

Conversation

@lx3133584

Copy link
Copy Markdown

Problem

When the port configured for @astrojs/node standalone mode is already occupied, the built server process exits with code 0 without logging any error message (#18282).

This happened because:

  1. standalone() returns the server's closed promise as done, which rejects on the server's error event. server.ts started the server but never handled done, allowing the rejection to become unhandled.
  2. serve-app.ts registers a process-level unhandledRejection listener that silently returns when requestContext.getStore() is undefined (i.e. outside an active request). This swallowed the rejection at boot time. Because no socket remained listening, the event loop emptied and Node exited cleanly with code 0.

Solution

  1. In packages/integrations/node/src/server.ts, catch errors on startServer().done, log them, and exit with code 1.
  2. In packages/integrations/node/src/serve-app.ts, log rejections occurring outside a request context and set process.exitCode = 1 rather than silently ignoring them.
  3. Added a regression test in packages/integrations/node/test/standalone-error.test.ts verifying that starting a standalone server when the port is occupied exits with code 1 and logs the EADDRINUSE error.
  4. Added patch changeset for @astrojs/node.

Fixes #18282

Testing

  • Ran packages/integrations/node/test/standalone-error.test.ts with verified RED / GREEN mutation testing:
    • Without the fix: exited with code 0 and empty stderr.
    • With the fix: exits with code 1 and logs the EADDRINUSE error.
  • Ran all existing tests in packages/integrations/node (Prerendering, Redirects, Aborted requests, etc.) to ensure no regressions.

🤖 Generated with Claude Code

When the standalone server encounters an error during bind (such as
EADDRINUSE), handle the server completion promise in server.ts rather
than dropping it as an unhandled rejection, and ensure serve-app.ts
logs and sets a non-zero exitCode for unhandled rejections outside
a request context.

Fixes withastro#18282

Co-Authored-By: Claude Code <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6c82c7f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/node Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the pkg: integration Related to any renderer integration (scope) label Oct 11, 2026
Co-Authored-By: Claude Code <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: integration Related to any renderer integration (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@astrojs/node standalone exits 0 without any output when its port is taken (EADDRINUSE swallowed)

1 participant