Repository navigation
fix(platform): fit the Hyperdrive origin connection limit to the database - #910
Open
Brooooooklyn wants to merge 1 commit into
Open
Brooooooklyn wants to merge 1 commit into
Brooooooklyn wants to merge 1 commit into
Conversation
…base The installer created the platform Hyperdrive without an origin connection limit, so Cloudflare's default (60 on the e2e account) could exceed a small database's max_connections. Under load the pool took every non-superuser slot and direct connections (upgrade, repair, psql) failed with 53300 for minutes at a time. Install, repair, and upgrade now read max_connections minus the reserved slots on the held lifecycle lock connection and lower the limit of the Hyperdrive Void created so five slots stay free. The limit is never raised, so it stays within the account plan. A separately managed Hyperdrive only gets a warning. 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. |
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
A live end-to-end run of the self-hosted platform, done while testing security audits (PR #886), ran about 15 queued scans on one install. The scans themselves were fine. The database was not. This bug is outside the security-audits feature, so it gets its own PR.
The install's PostgreSQL server had
max_connections = 25. The Hyperdrive config the installer created hadorigin_connection_limit = 60(the Cloudflare default for that account).pg_stat_activityshowed 18+ Hyperdrive connections whenever we could get in.Repro
max_connections(25 here; many hosted starter plans are this size).void platform installwith "Void creates the Hyperdrive".VOID_PLATFORM_DATABASE_URL(psql, orvoid platform upgrade).53300 remaining connection slots are reserved for roles with the SUPERUSER attributefor 15+ minutes at a time. The API also returned an intermittent 500 ("Failed to read project security", on adeployment_operationsquery).Root cause
On
main, the installer creates the Hyperdrive with noorigin_connection_limitand never changes it later:packages/void/src/cli/platform-installer-resources.ts:287callsclient.createHyperdrive(...).packages/void/src/cli/platform-cloudflare.ts:1009(createHyperdrive) posts onlyname,cachingandorigin.git grep origin_connection_limitfinds nothing inpackages/*/srcorplatform/packages/*/src.So Cloudflare's default limit applies. When that is above the server's non-superuser slots, the pool can take every slot.
Fix
readConnectionSlotsruns on the lifecycle-lock connection the installer already holds, so it opens no extra connection (platform-installer-database.ts).reserved_connectionsexists only on PostgreSQL 16+; older servers count it as 0.getHyperdriveConfignow readsorigin_connection_limit, and a newsetHyperdriveOriginConnectionLimitsends the PATCH (platform-cloudflare.ts).platform-hyperdrive-connections.tsholds the rule. It only ever lowers the limit, so it never sends a value above the account plan's maximum (Free is about 20). If Cloudflare reports no limit, it leaves the config alone.platform-install-provisioning.tsright after the existing Hyperdrive check, so existing installs are fixed by their nextvoid platform repairorupgrade.docs/guide/platform/installation/prerequisites.mdnow says what Void does and what is left to the user.Tests
packages/void/test/unit/platform-hyperdrive-connections.test.ts(new): 60 → 17 for a 22-slot database; no change when the limit already fits or is not reported; minimum of 5; adopted Hyperdrive only gets a warning; no calls when the lock cannot read slots.platform-cloudflare.test.ts: parsesorigin_connection_limitand sends the PATCH body.platform-database-lock.test.ts:readConnectionSlotsruns against real PostgreSQL (PGlite) through the lock wrapper.vp check(only errors are missing generatedplayground/*/.void/tsconfig.jsonin a fresh worktree; none in changed code), andvp run test. The 8 failures in that run were timeouts inplatform/packages/apiintegration tests while another worktree ran the same suite; those 6 files pass when rerun alone.🤖 Generated with Claude Code