fix: restore a saved undefined process.exitCode as an explicit 0 - #1086
Open
AntonOfTheWoods wants to merge 1 commit into
Open
fix: restore a saved undefined process.exitCode as an explicit 0#1086AntonOfTheWoods wants to merge 1 commit into
AntonOfTheWoods wants to merge 1 commit into
Conversation
PGlite saves and restores process.exitCode around engine calls that may run proc_exit(XX). On a clean host the saved value is undefined, and under bun assigning undefined to process.exitCode does not clear the current value — depending on the current value it is either a silent no-op or throws 'TypeError: exitCode must be an integer' — so the restore fails and the engine's proc_exit(99) boot sentinel survives, force-exiting an otherwise successful host process with code 99. close() previously masked this: _emscripten_force_exit(0) set an explicit 0 on the way out. Preserving the host exit code across close() (electric-sql#1059) removed that incidental reset and exposed the bug on every lane — under bun, a fully green run of the 0.5.5 release now exits 99. Route all three restore sites through a helper that writes 0 when the saved value was undefined; that is equivalent for exit status on every runtime. Repro against the 0.5.5 release, run with bun: import { PGlite } from '@electric-sql/pglite' const pg = await PGlite.create() await pg.exec('SELECT 1') await pg.close() // process exits 99 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PGlite saves and restores
process.exitCodearound engine calls that may runproc_exit(XX)(#init(),close(),execProtocolRaw). On a clean host the saved value isundefined, and under bun assigningundefinedtoprocess.exitCodedoes not clear the current value — depending on the current value it is either a silent no-op or throwsTypeError: exitCode must be an integer. The restore therefore fails, and the engine'sproc_exit(99)boot sentinel survives to process exit: a fully successful bun process exits with code 99.Until 0.5.4 this was masked by an accident:
close()'s_emscripten_force_exit(0)set an explicit0on the way out. #1059 (correctly) madeclose()restore the previously saved value instead — which removed the incidental reset and exposed the bug for every bun consumer of the 0.5.5 release. Repro, run with bun against@electric-sql/pglite@0.5.5:This also fails any downstream
bun testsuite that touches PGlite: every test passes and the runner still exits 99.The fix routes all three restore sites through one helper that restores a saved
undefinedas an explicit0, which is equivalent for exit status on every runtime. The added regression test asserts the boot sentinel never remains onprocess.exitCode; under bun the whole suite additionally force-exits 99 without the fix, so the lane goes red either way.🤖 Generated with Claude Code