Skip to content

3.x.x: give each rollups test fixture its own database so sibling migrations cannot time out its setup (#603) - #641

Merged
kiwidream merged 1 commit into
3.x.xfrom
kiwidream/603-rollups-lock-timeout
Oct 1, 2026
Merged

kiwidream merged 1 commit into
3.x.xfrom
kiwidream/603-rollups-lock-timeout

Conversation

@kiwidream

@kiwidream kiwidream commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Closes #603.

This makes the two rollups::tests lock-timeout flakes from #603 deterministic. The change is test-only. No assertion, timeout or production lock_timeout changes.

Problem

rollups::tests::with_database made a fresh schema in the shared test database and ran Ledger::connect(.., true) there. Migration takes MIGRATION_LOCK (0x505249534d000001, ledger.rs) with pg_advisory_xact_lock (ledger/migration.rs, migrate_schema). That call runs under the ledger pool's 5 s lock_timeout.

Advisory locks belong to a database, not a schema. So every lib-test fixture that migrates into the shared database waits on that one key. Once that queue is longer than 5 s, the rollup fixture's setup fails with the bare canceling statement due to lock timeout that #603 recorded. The error had no context, so it looked as though the test's own LOCK TABLE barrier had timed out.

A private PostgreSQL 16 server log (log_lock_waits=on, application names in the prefix) shows which statement it was. A failing rollup fixture's SELECT pg_advisory_xact_lock($1) was waiting on advisory lock [1347570003,1291845633], which is MIGRATION_LOCK. Six other fixtures' migrations were ahead of it in the queue. It was cancelled at 5.0 s. All 11 rollups cases set up this way, so whichever case was late in the queue failed. #603 saw two of them.

This is the same class as #410 (database-scoped advisory locks across per-fixture schemas) and #532/#537 (concurrent migrations against the 5 s lock timeout).

Change

crates/qbit-prism-server/src/rollups/tests.rs only:

  • with_database opens a database for each case with the existing FixtureDatabase helper (tests/support/ledger_database.rs, 3.x.x: Give each integration fixture its own database #410's fix). That helper sets the schema's search_path in the fixture URL and drops the database however the case ends: success, error, panic or cancellation. No case can queue on another fixture's migration any more.
  • The cases find the rollup's session in the cluster-wide pg_stat_activity by application_name. That name is still the fixture's unique generated schema name (53 bytes).
  • The connect-and-migrate step gets the context connecting and migrating the rollup fixture ledger, so a setup failure no longer looks like a failure of the case's own SQL.
  • A case's error now carries any cleanup failure as context (FixtureDatabase::close) instead of dropping it. After a panic, the cleanup error is printed and the panic re-raised, as before.

Tests

On a private PostgreSQL 16 (fsync on) with PRISM_TEST_REQUIRE_INTEGRATION=1, one test binary at a time.

Deterministic reproduction. A second session holds MIGRATION_LOCK in the gate database for the whole run (SELECT pg_advisory_lock(x'505249534D000001'::bigint)), as a sibling fixture's migration does. The script checks that the lock is granted before the binary starts and is still held when it exits.

binary filter runs result
base (4f4b218) the two #603 cases, --exact 3 3/3 fail, 6/6 canceling statement due to lock timeout, after 5.01 s
this PR the two #603 cases, --exact 20 20/20 pass (2/2 each)
base rollups::tests 1 4 passed, 7 failed (every PostgreSQL case)
this PR rollups::tests 5 5/5 pass (11/11 each)

No fixture databases or holder sessions were left behind afterwards.

Checks:

  • cargo fmt --all -- --check: clean.
  • cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings: clean.
  • cargo test --locked -p qbit-prism-server --lib at the PR head: 599 passed, 0 failed, 2 ignored, in 127.6 s on an unloaded host. No fixture databases were left behind.

test/prism-gated-tests.txt is unchanged, because no test ID changed.

Not run here and why

The build host has no qbitd and no Docker, so live_regtest and the other real-node suites were not run. This PR does not touch them.

Merge notes

  • One signed commit on 3.x.x at 4f4b218. 3.x.x has since moved by two commits, neither of which touches these files, and the branch merges cleanly.
  • The test role needs CREATEDB. That is not new: the other lib suites that already use FixtureDatabase (partitions::acquire_tests, payout_state_tests, snapshot_delta, miner_submit_acquire_tests) need it, and CI has it.

Follow-up candidates (not fixed here)

While reproducing this, other lib tests failed with the same bare canceling statement due to lock timeout signature: ledger::candidates::park_tests (3 cases), ledger::connect::acquire::tests::postgres_checkout_boundaries_and_callers, ledger::connect::acquire::job_tests::postgres_job_sql_wait_errors_and_cancellation_do_not_change_checkout_samples, coordinator::window_switch_tests (3 cases), coordinator::window_ref_tests::a_refresh_publishes_the_reference_for_the_window_it_captured and coordinator::same_tip_republish_tests::a_build_overtaken_by_a_revision_or_fee_change_is_discarded. Their files also migrate into the shared gate database without FixtureDatabase, so they are probably the same MIGRATION_LOCK queue. I have not checked which statement timed out for each. They are candidates for the same conversion.

Separate note: the four CI flakes from the #626 handover

The four intermittent CI failures that the #626 handover listed as "re-run, not filed" are now tracked:

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…rations cannot time out its setup (#603)

The rollups::tests fixture created a schema in the shared test database and
ran Ledger::connect(.., true) there. Migration takes MIGRATION_LOCK
(0x505249534d000001) with pg_advisory_xact_lock, and advisory locks are
scoped to the database, not the schema, so every fixture in the lib binary
that migrates into that database queues on one key under the ledger pool's
5 s lock_timeout. On a loaded host the queue passed 5 s and setup failed
with a bare "canceling statement due to lock timeout", which is what #603
recorded. The server log of a reproduction showed the timed-out statement
was the rollup fixture's SELECT pg_advisory_xact_lock($1), sixth in a queue
of other fixtures' migrations.

The fixture now opens a per-case database with the shared
FixtureDatabase helper (#410's fix for the same class of contention), keeps
its schema name as the application_name the cases look up in
pg_stat_activity, and attaches setup context to the connect/migrate step.
The test error now keeps any cleanup failure as context instead of dropping
it. No assertion, timeout or production lock_timeout changes.

Holding MIGRATION_LOCK in the gate database from a second session, the
base fails both #603 cases 3/3 with that error; with this change they pass
20/20 and all 11 rollups::tests pass 5/5.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T16:37:33.516451Z bcc53a1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kiwidream

Copy link
Copy Markdown
Member Author

Re-running CI: the shard 1 failure was the known real_node_smoke flake (#638), and this token can't re-run workflows, so the PR is being closed and reopened.

@kiwidream kiwidream closed this Oct 1, 2026
@kiwidream kiwidream reopened this Oct 1, 2026
@kiwidream

Copy link
Copy Markdown
Member Author

Re-running CI: shard 0 was cancelled at its 30-minute timeout with no failing test. That's pre-existing variance; 3.x.x's own run on 8dbdb57 was cancelled the same way.

@kiwidream

Copy link
Copy Markdown
Member Author

Re-running CI after #648 (the #647 fix: balanced PostgreSQL shards, 45-min cap) merged into 3.x.x as 2e22347c. The earlier failures were shard timeouts.

@kiwidream kiwidream closed this Oct 1, 2026
@kiwidream kiwidream reopened this Oct 1, 2026
@kiwidream

Copy link
Copy Markdown
Member Author

Re-running CI: the previous re-run started while GitHub was still recomputing this PR's merge ref after #648 merged, so it used the old 30-minute cap and shard layout (shard 1 was cancelled at 30 min, with every test passing). The merge ref is current now.

@kiwidream kiwidream closed this Oct 1, 2026
@kiwidream kiwidream reopened this Oct 1, 2026
@kiwidream
kiwidream merged commit eedf331 into 3.x.x Oct 1, 2026
154 of 166 checks passed
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