Skip to content

3.x.x: PostgreSQL warns there is already a transaction in progress on the share-append path under commit-deadline cancellations #482

Closed

Description

@Anatolie

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

  1. Reproduce with a proxy delay and a short commit timeout; log the connection id with the warning and correlate with the cancelled append.
  2. Read sqlx 0.8's cancellation and pool-return behaviour for begin/dropped transactions (transaction_depth, the lazy ROLLBACK, test_before_acquire/after_release) and state which explanation the code supports.
  3. If a leftover transaction can hold ORDER_LOCK or commit foreign statements, add the guard (a ROLLBACK/DISCARD on release after a cancelled append, or idle_in_transaction_session_timeout) with a test that injects a cancellation after BEGIN.
  4. If it is benign, record why in docs/prism-rejections.md or 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

  1. kiwidream commented on Sep 24, 2026

    @kiwidream
    Member

    Root cause and guard in #515 (ledger-482-cancelled-append-transaction). Status: In review.

  2. kiwidream commented on Sep 24, 2026

    @kiwidream
    Member

    Closed by #515, squash-merged to 3.x.x as 67b47cf5 on 2026-09-24. Root cause: sqlx 0.8.6 counts a transaction only after the BEGIN reply, so a future dropped inside BEGIN (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's BEGIN landed inside it. No advisory lock can be held across it; a directly acquired statement could run inside the leftover. Guard: ledger::shielded_begin for owned transactions and the collector; an append connection whose BEGIN did not complete is detached and closed rather than returned. Two gated tests in tests/ledger_cancelled_begin.rs fail on the base and pass on the head; successful append path unchanged (same ten statements, verified on the wire). Written argument and rejected alternatives in docs/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: plain Transaction::begin on the partition-retry and rollup paths.

  3. added a commit that references this issue on Sep 25, 2026
  4. added 3 commits that reference this issue on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions