Repository navigation
Description
Workstream A · P2 · Size S · Tracker #261 · Part of #260 · Follow-up of #447 (workstream proposed)
Problem
In every D1 run of #447 the frontend log holds PostgreSQL's WARNING: there is already a transaction in progress, which is BEGIN arriving on a connection that already has an open transaction (Harness observations (#447), item 6). Across the 33 D1 runs on a1937054: 10,303 occurrences, 8,431 in slow_database and 1,866 in the drain after it, where appends are being cancelled at the share-commit deadline (share commit deadline passed before COMMIT was sent, thousands per run in that phase, with pool timed out while waiting for an open connection). Five more are in flush-control phases that logged the same cancellations, and one is in the steady_state of d1-dense400k-fe1-async-r1, a phase that logged no such cancellation, so the deadline is not the only trigger.
Every run in which it appears reconciled exactly (no divergence, no durability finding), so no effect on the ledger was observed. It was not investigated, and nothing in the repository mentions it.
What it could mean, and what needs ruling in or out: a cancelled append (the tokio::time::timeout around the save, the #324 mechanism) dropping its future after BEGIN was written but before the reply was read, leaving the connection's server-side transaction open while sqlx believes none is; the next user's BEGIN then lands inside it. If that transaction had already taken pg_advisory_xact_lock(ORDER_LOCK), the lock is held until the connection's next COMMIT/ROLLBACK, by whoever gets the connection, and statements from the cancelled attempt could commit with the next share's. The exact reconciliation in 33 runs says the visible cases were harmless; it does not say why.
Proposed change
- Reproduce with a proxy delay and a short commit timeout; log the connection id with the warning and correlate with the cancelled append.
- Read sqlx 0.8's cancellation and pool-return behaviour for
begin/dropped transactions (transaction_depth, the lazyROLLBACK,test_before_acquire/after_release) and state which explanation the code supports. - If a leftover transaction can hold
ORDER_LOCKor commit foreign statements, add the guard (aROLLBACK/DISCARDon release after a cancelled append, oridle_in_transaction_session_timeout) with a test that injects a cancellation afterBEGIN. - If it is benign, record why in
docs/prism-rejections.mdor the ledger docs so the next reader of a frontend log does not have to ask.
Acceptance criteria
- The trigger is named with a reproduction, including the one occurrence without a deadline cancellation.
- Either a guard with a test, or a written argument that nothing can commit or stay locked across it.
Related
#324 (dropped future mid-COMMIT), #272 (ledger deadline and retry-safety tests), #447, #473.
Found by #447. Recorded in #473 (docs/prism-throughput-measurements.md, "Production-window matrix on a1937054 (#447)"). Raw side reports, artifacts and frontend logs are kept outside the repository and cited by run id.
Activity
kiwidream commentedon Sep 24, 2026
Root cause and guard in #515 (
ledger-482-cancelled-append-transaction). Status: In review.3.x.x: keep a ledger future cancelled inside BEGIN from leaving its t…
kiwidream commentedon Sep 24, 2026
Closed by #515, squash-merged to
3.x.xas67b47cf5on 2026-09-24. Root cause: sqlx 0.8.6 counts a transaction only after theBEGINreply, so a future dropped insideBEGIN(share-commit deadline abort, miner-disconnect drop, the collector's 3 s deadline, session allocation under the subscribe timeout) returned a connection whose server side was in a transaction; the next checkout'sBEGINlanded inside it. No advisory lock can be held across it; a directly acquired statement could run inside the leftover. Guard:ledger::shielded_beginfor owned transactions and the collector; an append connection whoseBEGINdid not complete is detached and closed rather than returned. Two gated tests intests/ledger_cancelled_begin.rsfail on the base and pass on the head; successful append path unchanged (same ten statements, verified on the wire). Written argument and rejected alternatives indocs/prism-ledger-ops.md. Adversarial verification on the PR: approve, four lows (close timeout, tracing span, one missing assertion, one doc sentence) left as follow-ups. Residual named in the doc: plainTransaction::beginon the partition-retry and rollup paths.Merge 3.x.x into the #479 ORDER_LOCK hold branch
3.x.x: cut the share append's ORDER_LOCK hold from nine client round …
docs: the #482 residual and the partition-ensure lock say what the co…
3.x.x: partition maintenance and the rollup sweep begin their transac…
docs: the #482 residual and the partition-ensure lock say what the co…