fix(db): release read transactions — no more idle-in-transaction on Postgres - #8
Merged
Conversation
…ostgres With autocommit=False every SELECT opened a transaction that nothing ended, so pooled request threads and the chat websocket idled inside transactions, pinning ACCESS SHARE locks. Lock-safe plugin migrations (ALTER TABLE) then timed out on every boot in production, columns were never added, and saves silently dropped fields for the missing columns (200 OK, edits lost). _PgConn now tracks pending writes and rolls back right after a read when no write is uncommitted and no explicit transaction (submit/cancel) is active. psycopg's client-side cursor has already buffered the rows, so fetching after the release works. Write flows and their atomicity are byte-for-byte unchanged. tests/test_txn_release.py covers the semantics plus the real failure mode: a quiet reader thread + ensure_column now succeeds. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…key/value Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes the production migration-starvation bug: with
autocommit=Falseevery SELECT opened a transaction that nothing ended, so pooled request threads (and the chat websocket) idled inside transactions holdingACCESS SHARElocks. The lock-safe plugin migrations'ALTER TABLEthen hit its lock timeout on every boot (observed on erp.lambda.dev: internal migrations 0005/0006/0008/0009 failing since 0.6.3), columns were never created, and_persist()silently dropped edits to those fields — saves returned 200 OK but nothing stuck.Fix:
_PgConntracks pending writes and rolls back immediately after a read when no write is uncommitted and no explicit transaction (submit/cancel) is active. psycopg's client-side cursor already buffered the result set, so post-release fetching works. Write flows and atomicity unchanged; SQLite untouched.Test:
tests/test_txn_release.py(Postgres CI) — read releases, helpers release, interleaved reads don't roll back pending writes, explicit-transaction reads keep their snapshot, and the real failure mode: a quiet reader thread +ensure_columnsucceeds.🤖 Generated with Claude Code