Repository navigation
3.x.x: Keep the pg_restore session out of the fixture pool - #422
Merged
Merged
Conversation
support::recovery::restore ran the SQL that pg_restore emits on a connection borrowed from the fixture pool. That SQL opens with session SET statements that survive COMMIT: PostgreSQL 16 emits statement_timeout = 0, lock_timeout = 0 and idle_in_transaction_session_timeout = 0 besides the search_path reset, and sqlx 0.8.6 returns a pooled connection through a spawned task with no session reset, so a later pooled query inherited whichever of them landed on the same connection. Run the restore on a dedicated PgConnection instead: one transaction, commit, then close. The restore result is evaluated before the close result so a failed close cannot hide the restore error. The session is built from the fixture URL, which pins search_path to the target schema, and the helper checks current_schema() against the target before restoring into it. Drop #391's in-transaction search_path reset. It returned the pooled session to the fixture schema before reuse; the dedicated session is closed and never reused, so the mechanism that produced the intermittent "relation does not exist" failure is gone rather than patched over. The new test pins search_path along with the timeouts. The new gated test opens its target with the ledger's operator timeouts on the URL, because the fixture's plain pool defaults every setting pg_restore touches to 0 and would not observe the leak. It waits for sqlx to return every connection and then reads all of them, so the check does not depend on release scheduling. Before this change it fails on every run with "pooled lock_timeout is "0", expected "5s"". Closes #411. Co-Authored-By: Claude Fable 5.1 <[email protected]>
The pg_restore session helper evaluated the restore result before the close result so a failed close could not hide why the restore failed, but nothing tested that order: swapping the two lines left every migration_rollback test green, because no test injects a failing close against a live connection. Move the precedence into a pure helper, restore_outcome, and unit-test all four combinations directly. When both fail, the restore error is returned with the close failure appended to its message, so the operator reads the restore error first and the close failure is not lost either. The session is still closed on both paths; only which error is reported is pinned. Swapping the precedence in the helper now fails restore_outcome_prefers_the_restore_error_when_both_fail. Follow-up to #411. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Codex Review SummaryThis 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 was referenced Sep 16, 2026
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.
support::recovery::restoreran the SQLpg_restoreproduced on a connectionborrowed from the fixture pool and then handed that connection back. The script
is not pure DDL: it opens with session
SETstatements, and those surviveCOMMIT.#391 fixed the first symptom —
pg_restoreemitsSELECT pg_catalog.set_config('search_path', '', false), and a pooledconnection carrying an empty
search_pathbroke a later schema-qualifiedDELETEwhose trigger body resolves unqualified ledger tables. That fixrestores
search_pathinside the same transaction. The rest of the block wasstill returned:
statement_timeout,lock_timeoutandidle_in_transaction_session_timeout, all set to0. sqlx 0.8.6 releasespooled connections through a spawned task with no reset, so whether a later
statement lands on an affected connection is a scheduling accident.
The restore now runs on a dedicated
PgConnection, in one transaction, and thatconnection is closed rather than returned.
after_releasewas deliberatelynot used: a pool-wide reset hook masks the class of problem instead of removing
this instance, and a second pool would have the same defect as the shared one.
Closes #411
What changed, precisely
restoreopensPgConnection::connect(&target.url), assertscurrent_schema()is the target schema before doing anything, runs the scriptin one transaction, commits, and closes the connection.
cannot hide why the restore failed. When both fail, the restore error is
returned with the close failure appended to its message, so neither is lost.
That precedence is now a named helper,
restore_outcome, with unit tests overall four combinations.
search_pathreset is removed in the same commit. On asession that is closed and never returns to a pool it is dead code, and its
comment — "Return this pooled connection to the fixture's schema before
reusing it" — would have become false. The symptom is not reintroduced; the
mechanism that caused it is gone. The new test pins
search_pathalongside thetimeouts to prove it.
Verification
Toolchain 1.98.1. PostgreSQL 16.15.
migration_rollbackat default concurrency against a live database:8 passed, 0 failed, including
frozen_2x_backup_restore_reconciles_before_ack_and_exposes_post_ack_loss.cargo clippy --locked -p qbit-prism-server --all-targets -- -D warningsandcargo fmt --check: clean.New gated test
frozen_2x_backup_restore_session_settings_stay_off_the_fixture_poolrestoresinto a fixture, waits until every pooled connection is idle, acquires all of
them and reads each session setting, then repeats the probe after a failed
restore. Manifest goes 367 → 368; with
GITHUB_JOB=prism-native-postgresandno database it fails rather than skips.
Reverting the fix fails that test, verbatim:
Error: after restore: pooled lock_timeout is "0", expected "5s": the pg_restore session reached the fixture poolMutation testing, three mutations, each killed by a named test:
frozen_2x_backup_restore_session_settings_stay_off_the_fixture_poolfrozen_2x_backup_restore_reconciles_before_ack_and_exposes_post_ack_loss, withError: restore session resolves "public", not the target schemarestore_outcome_prefers_the_restore_error_when_both_failThe third was run twice: it initially survived, and the helper and its unit
tests were added in response.
How much of a live hazard this actually was
#411 says the leak was inferred, not reproduced, and confirming it was part
of the work. It is worth being precise about what the reproduction shows.
recovery::Database's pool sets noafter_connect, so PostgreSQL's own defaultsfor the three timeouts are already
0— identical to whatpg_restoresets. Theledger fixtures that do pin operator timeouts never run a restore, and since
#410 gave each ledger fixture its own database, a leaked session cannot travel
from the recovery fixture to another test file at all. So the failure #411
describes — a test expecting a lock to time out instead hanging to the outer
timeout — was not reachable on this tree.
The reproduction therefore configures the recovery fixture's URL with the same
timeout values
Ledger::connectpins, and shows that the restore session'szeros survive into a later query on that fixture's own pool. That is a faithful
demonstration of the mechanism, inside one fixture, which is the only place it
can now be shown. It is not a demonstration of a failure that was occurring.
The fix is still worth landing on that basis: it removes a session-state escape
that is invisible until a fixture starts pinning a setting, in the area that has
already cost two qualification runs.
Observation, not addressed here
#410 introduced
tests/support/ledger_database.rs— one database per ledgerfixture — and moved eight test files onto it.
recovery.rswas left on the oldermodel:
Database::openstill doesCREATE SCHEMAinside the gate's shareddatabase and connects with
options=-csearch_path=<schema>. Two fixture modelsnow coexist in one test tree, and this is the only file still on the older one.
Moving it is not a substitute for this fix and is not attempted here: a
per-fixture database still hands out pooled connections, so the restore
session's
lock_timeout = 0would still return to that fixture's own pool andstill reach a later query in
migration_rollback. The two changes areorthogonal. The inconsistency is recorded here so it is not lost.
A note for whoever reads the history
54c0f889, the squash commit for #410, listsv3.0.0 test: isolate restore session settingsas its third bullet — the subject of15bafb7f, thesuperseded prior implementation this issue names. That change did not land.
#410 does not touch
tests/support/recovery.rs; the file's blob is identical at3b654b5c, at #410's pre-merge head and at758f46dc. #410's PR body isexplicit and correct about this — it says
support/recovery.rsdoes not appearin the diff, that the commit is kept as a superseded attempt, and that the
remaining timeouts are worth a separate issue. Only the squash message misleads.
This PR is the change that bullet appears to promise.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.