Repository navigation
fix(platform): survive a dropped lifecycle lock connection during upgrade - #909
Open
Brooooooklyn wants to merge 1 commit into
Open
Brooooooklyn wants to merge 1 commit into
Brooooooklyn wants to merge 1 commit into
Conversation
…rade The PostgreSQL lifecycle lock holds one pg client for the whole lifecycle command. It had no 'error' listener, so a server reset while Workers deployed (read ECONNRESET) became an unhandled 'error' event and killed the CLI before its failure handler ran. Listen for errors on the pool and the lock client. Later lock operations fail with a clear "connection was closed, rerun" message, and release skips the unlock (the server already ended the session lock) and destroys the broken client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
🚀 Deploying Preview to Cloudflare 🚀Preview URL: https://fix-upgrade-pg-error-void-cloud.voidzero-docs.workers.dev (commit 076ea8a)This URL reflects your latest Preview deploymentPreview Deployments by commit
|
This branch has not been deployed
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.
How it was found
During a live end-to-end run of the self-hosted platform while testing the security audits work (PR #886),
void platform upgradecrashed halfway through and left the platform paused. The crash is not related to security audits. It is in the upgrade command's PostgreSQL lifecycle lock, which every install, upgrade, repair, enable and disable uses.Repro
void platform upgrade --runtime <path> --yes.Expected vs actual
▲ Something went wrong/node:events Unhandled 'error' event/Error: read ECONNRESET ... Emitted 'error' event on Client instance. No failure handling runs. Operator API calls return 503 "the platform is paused for an upgrade or repair" andplatform statusshows "Saved operation: upgrade — deploying" until the upgrade is rerun.Root cause
packages/void/src/cli/platform-installer-database.ts:207-237(acquirePlatformDatabaseLifecycleLock) checks out onepgclient withpool.connect()and holds it for the whole lifecycle command, because the lock is a session advisory lock. It never adds an'error'listener to the client or the pool.pgremoves the pool's own error listener from a client while it is checked out. When the socket is reset,pgemits'error'on the client. With no listener, Node throws it as an unhandled'error'event and the process exits.Fix
In
acquirePlatformDatabaseLifecycleLock:pool.on('error')andclient.on('error'). The client listener keeps the first error.QueryConnectionwrapper. After a lost connection, each lock call (checkpoint, verify, migrate, reads) fails withplatform: The PostgreSQL connection that holds the lifecycle lock was closed (read ECONNRESET). Rerun the command to continue.That error goes through the normal upgrade failure path.pg_advisory_unlock, because the server already ended the session lock with the connection. Release the client with the error sopgdestroys it instead of pooling it. Then end the pool. Release no longer throws a second error that would hide the first.Keeping traffic paused after a failed cutover is intended: the failure handler keeps the routing gate closed and the next run continues from there. This PR does not change that. It only replaces the crash with the normal failure path and a clear rerun message.
Not changed:
platform-auth-recovery.tsopens its own short-lived lock connection. It is a separate command and is left for a follow-up if needed.Tests
packages/void/test/unit/platform-database-lock.test.ts: a lock client and pool that areEventEmitters. Emitting'error'(ECONNRESET) no longer throws. LaterverifyDatabaseandreadAdministratorSetupreject with the clearplatform:message. Release resolves, sends no SQL, and destroys the client. The test fails onmainwith the unhandled'error'event.pgmocks inplatform-database-lock.test.tsandplatform-database-ssl.test.tsto accepton().vp check(no errors outside playground.void/tsconfig.jsonfiles that only exist after a playground build), andvp run test. Allpackages/*groups pass. The platform groups passed or timed out only while the test machine was put to sleep (about 980 s gaps in the power log); the platform integration tests that use this lock (zero-trust-uninstall,platform-bootstrap) pass when run alone. CI runs the full suite.🤖 Generated with Claude Code