Skip to content

fix: preserve host process.exitCode when closing PGlite#1059

Open
zakcutner wants to merge 1 commit into
electric-sql:mainfrom
zakcutner:fix/preserve-exit-code-on-close
Open

fix: preserve host process.exitCode when closing PGlite#1059
zakcutner wants to merge 1 commit into
electric-sql:mainfrom
zakcutner:fix/preserve-exit-code-on-close

Conversation

@zakcutner

Copy link
Copy Markdown

Closing a PGlite instance resets the host process's process.exitCode to 0. This wipes out whatever the host had already set.

The cause is close() calling _emscripten_force_exit(0). Emscripten implements exit as quit_ = (e, r) => { throw process.exitCode = e, r }, so it writes process.exitCode = 0 on the host Node process. The #init() and execProtocolRaw() paths already save and restore process.exitCode around their Emscripten calls, but close() was missing the same guard.

This adds that guard. It reuses the existing pglUtils.pgliteProc.exitCode save and restore pattern in a finally, like execProtocolRaw(). It also adds a test next to the existing restores process.exitCode one, plus a changeset.

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().
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