Repository navigation
fix: preserve host process.exitCode when closing PGlite - #1059
Merged
tdrz merged 1 commit intoJul 28, 2026
Merged
Conversation
close() calls _emscripten_force_exit(0), whose Emscripten runtime sets process.exitCode = 0 and clobbers any exit code the host process had already set. Save and restore process.exitCode around the call, matching the existing guards in #init() and execProtocolRaw().
AntonOfTheWoods
added a commit
to pgxsinkit/pglite
that referenced
this pull request
Aug 18, 2026
Moved pgx-publish back onto upstream/main (0.5.5). initdb-fs-leak (electric-sql#1060) and formatQuery positional-params (electric-sql#1056) merged upstream, so both are dropped from the fork; the remaining stack carries only changes still absent upstream: transaction-end sync (+ already-closed completion), the IDBFS durability hardening and relaxed-concurrency restore, the non-exclusive relaxed-sync latch (scoped), the opfs-ahp instrumentation, and the close() relaxed-sync drain. Conflicts re-applied onto the new base: - pglite.ts close(): kept the IDBFS-hardening deferred-throw structure and folded upstream electric-sql#1059's process.exitCode save/restore into force_exit. - base.ts transaction(): our flag-repositioning + rollback/already-closed sync guards now coexist with upstream electric-sql#1062's closed=true-before-ROLLBACK and checkClosed() gates. Co-Authored-By: Claude Opus 4.8 <[email protected]>
AntonOfTheWoods
added a commit
to pgxsinkit/pglite
that referenced
this pull request
Aug 18, 2026
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 `process.exitCode = undefined` is a no-op that leaves the current value in place — so the restore silently failed and the engine's proc_exit(99) boot sentinel survived, 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 — a green bun test run 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. Co-Authored-By: Claude Opus 5 <[email protected]>
AntonOfTheWoods
added a commit
to pgxsinkit/pglite
that referenced
this pull request
Aug 18, 2026
0.5.5-pgx.1 regressed every bun host lane: upstream electric-sql#1059's process.exitCode save/restore across close() removed the incidental _emscripten_force_exit(0) reset that had been masking a failed restore, so the engine's proc_exit(99) boot sentinel reached process exit. Green pgxsinkit unit shards exited 99. Co-Authored-By: Claude Opus 5 <[email protected]>
AntonOfTheWoods
added a commit
to pgxsinkit/pglite
that referenced
this pull request
Sep 12, 2026
Moved pgx-publish back onto upstream/main (0.5.5). initdb-fs-leak (electric-sql#1060) and formatQuery positional-params (electric-sql#1056) merged upstream, so both are dropped from the fork; the remaining stack carries only changes still absent upstream: transaction-end sync (+ already-closed completion), the IDBFS durability hardening and relaxed-concurrency restore, the non-exclusive relaxed-sync latch (scoped), the opfs-ahp instrumentation, and the close() relaxed-sync drain. Conflicts re-applied onto the new base: - pglite.ts close(): kept the IDBFS-hardening deferred-throw structure and folded upstream electric-sql#1059's process.exitCode save/restore into force_exit. - base.ts transaction(): our flag-repositioning + rollback/already-closed sync guards now coexist with upstream electric-sql#1062's closed=true-before-ROLLBACK and checkClosed() gates. Co-Authored-By: Claude Opus 4.8 <[email protected]>
AntonOfTheWoods
added a commit
to pgxsinkit/pglite
that referenced
this pull request
Sep 12, 2026
0.5.5-pgx.1 regressed every bun host lane: upstream electric-sql#1059's process.exitCode save/restore across close() removed the incidental _emscripten_force_exit(0) reset that had been masking a failed restore, so the engine's proc_exit(99) boot sentinel reached process exit. Green pgxsinkit unit shards exited 99. Co-Authored-By: Claude Opus 5 <[email protected]>
AntonOfTheWoods
added a commit
to pgxsinkit/pglite
that referenced
this pull request
Sep 12, 2026
Moved pgx-publish onto upstream/main (0.5.8, ae182ff). The remaining stack carries only changes still absent upstream: transaction-end sync (plus the already-closed-transaction completion), the IDBFS durability hardening and relaxed-concurrency restore, the non-exclusive relaxed-sync latch (scoped), the opfs-ahp instrumentation, the close() relaxed-sync drain, the BasePGlite export and the live-query refresh/diff-key fixes. Dropped: the explicit-zero exit-code restore (0.5.5-pgx.2, and its changeset). Upstream electric-sql#1087 and electric-sql#1100 removed the process.exitCode save/restore sites entirely — the engine now reports exit status through _pgl_setPGliteExitStatus — so the helper had nothing left to restore. Its version-bump commit is kept as history. Conflicts re-applied onto the new base: - pglite.ts close(): kept the hardened structure (transaction/query mutex nesting, pending-sync drain, deferred final-sync and close-hook failures, closeFs in a finally, no serialize.end()) and replaced the folded electric-sql#1059 exitCode save/restore with upstream 0.5.8's exit tail — force_exit(0) with `this.mod = undefined` in the finally. - pglite.ts #init(): upstream removed the prevExitCode capture and its restore that bracketed the method, so the fork's #cleanupFailedInit, #initialSyncFs and #syncToFsStrict now follow a bare closing brace. - pglite.ts execProtocolRawSync(): upstream's body — the _pgl_setPGliteExitStatus(-2) longjmp check and a finally with no exit-code restore — plus the fork's #checkSynchronousFsSyncState() prologue. - packages/pglite/package.json: upstream's rewritten test:bun script kept alongside the fork's package name, repository url and publish:pgx:* scripts. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_019muxX7JzHorerHQedWXRoz
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.
Closing a PGlite instance resets the host process's
process.exitCodeto0. This wipes out whatever the host had already set.The cause is
close()calling_emscripten_force_exit(0). Emscripten implements exit asquit_ = (e, r) => { throw process.exitCode = e, r }, so it writesprocess.exitCode = 0on the host Node process. The#init()andexecProtocolRaw()paths already save and restoreprocess.exitCodearound their Emscripten calls, butclose()was missing the same guard.This adds that guard. It reuses the existing
pglUtils.pgliteProc.exitCodesave and restore pattern in afinally, likeexecProtocolRaw(). It also adds a test next to the existingrestores process.exitCodeone, plus a changeset.