Commit a9dd2e3
Close read txn at request end (afterCompletion) + idle-in-xact safety net (#118) (#58)
* test: failing regression for #118 — read txn must close on afterCompletion
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix(instance): implement afterCompletion to close read txn at request end (#118)
ZODB calls _storage.afterCompletion() after every transaction
commit/abort and on Connection.close(). Previously
PGJsonbStorageInstance did not define it, so the hook was a silent
no-op and the REPEATABLE READ snapshot opened by poll_invalidations()
persisted across requests. Each lingering read tx held a virtualxid
that blocks CREATE INDEX CONCURRENTLY indefinitely under load.
The new method delegates to _end_read_txn() (idempotent) and never
propagates exceptions — a connection killed externally just gets
logged; the next operation rebuilds via the pool.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test: edge cases for afterCompletion (idempotent, post-tpc, killed conn, end-to-end)
The end-to-end test verifies that after Connection.close(), the
backend's pg_stat_activity state is 'idle' (not 'idle in transaction')
— exactly the conditions that previously blocked CIC.
Note: mid-request transaction.commit/abort fires our afterCompletion,
but ZODB.Connection.afterCompletion immediately follows up with
newTransaction() → poll_invalidations() which re-opens the read tx
for the next implicit transaction. The fix's actual win is at
Connection.close() (pool return / request end), which the end-to-end
test pins down.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* test: failing regression for default idle_in_transaction_session_timeout (#118)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* feat(pool): set idle_in_transaction_session_timeout on every conn (#118)
Defense in depth for any leaked virtualxid that bypasses
afterCompletion (SIGKILL-ed worker, third-party plugin, etc.).
Default 60_000 ms, env-overridable via ZODB_PGJSONB_IDLE_IN_XACT_TIMEOUT_MS.
Set to 0 to disable.
Replaces the inline `lambda` configure with a named helper that also
applies the timeout setting alongside autocommit.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs: changelog + spec + plan for #118 read-tx fix
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent ed2a9a5 commit a9dd2e3
6 files changed
Lines changed: 1199 additions & 1 deletion
File tree
- docs/superpowers
- plans
- specs
- src/zodb_pgjsonb
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
5 | 23 | | |
6 | 24 | | |
7 | 25 | | |
8 | 26 | | |
9 | 27 | | |
10 | 28 | | |
11 | 29 | | |
| 30 | + | |
12 | 31 | | |
13 | 32 | | |
14 | 33 | | |
| |||
0 commit comments