Skip to content

fix: replace async-exit-hook with exit-hook to preserve process.exitCode#31

Open
AmineMaila wants to merge 1 commit into
leinelissen:mainfrom
AmineMaila:fix-exit
Open

fix: replace async-exit-hook with exit-hook to preserve process.exitCode#31
AmineMaila wants to merge 1 commit into
leinelissen:mainfrom
AmineMaila:fix-exit

Conversation

@AmineMaila

Copy link
Copy Markdown

Description

Replaces async-exit-hook with exit-hook to fix a bug where process.exitCode was always overridden to 0 on process exit.

async-exit-hook unconditionally calls process.exit(0) after its cleanup hooks run, ignoring any process.exitCode set by the application. The exit-hook package (by the same author, sindresorhus) hooks into process exit events without forcing the exit code, preserving whatever process.exitCode was set.

I encountered this while using vitest and embedded-postgres together for testing — when a test failed, vitest sets process.exitCode = 1, but async-exit-hook would force it back to 0, causing CI pipelines to incorrectly report the test run as successful.

Changes

  • packages/embedded-postgres/package.json: Replaced async-exit-hook dependency with exit-hook
  • packages/embedded-postgres/src/index.ts: Updated import from AsyncExitHook to asyncExitHook, removed the done callback parameter from gracefulShutdown, added a 5-second wait timeout
  • packages/embedded-postgres/tests/index.test.ts: Added test verifying that process.exitCode is preserved when using EmbeddedPostgres
  • packages/embedded-postgres/tests/helpers/exit-code-test.mjs: Helper script for the exit code test

Testing

  • All 8 existing + new tests pass
  • Verified that a child process using EmbeddedPostgres with process.exitCode = 42 exits with code 42 (not 0)

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.

1 participant