fix(fetch): avoid holding DB sessions across GitHub RPCs - #59
Merged
Conversation
ewhauser
marked this pull request as ready for review
August 7, 2026 03:34
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.
Summary
Root cause
BeginObservationacquired a dedicated pgxpool connection and held a session-level advisory lock across the authoritative GitHub request. Branch reconciliation can run four pages with up to 25 targets each, so slow remote responses could reserve roughly 100 connections and starve River leadership, producers, completion, and budget lease renewal even when PostgreSQL itself was healthy.The replacement token snapshots the entity's last committed observation version and immediately releases the query connection. After remote I/O, the entity transaction takes the existing transaction-scoped advisory lock, rejects the response if another entity write committed in the meantime, and advances the version atomically with cache, outbox, and follow-up writes.
Impact
GitHub RPC fanout is now independent of pgxpool capacity. Concurrent responses remain monotonic, including equal-upstream-version races, without retaining a transaction, advisory-lock session, or reserved connection during network I/O.
Validation
go test ./...go vet ./...git diff --checkTestSlowBranchPagesDoNotStarveSmallDatabasePoolThe PostgreSQL-backed tests require
TEST_DATABASE_URL; the new integration regression was discovered locally but skipped because that variable was unset. It will run in the repository's database-enabled CI environment.Fixes #58