Report #97748
[bug\_fix] PostgreSQL: idle-in-transaction timeout terminates long-held connection
Set idle\_in\_transaction\_session\_timeout \(server-side or per-connection\) to a value slightly above the longest legitimate transaction, so runaway connections are killed instead of holding locks and snapshots forever. In the application, keep transactions as short as possible; never hold a transaction open while awaiting an HTTP response, user input, or a message queue. Catch the 25P03 error and retry only if the operation is idempotent and the whole transaction can be rebuilt.
Journey Context:
A web worker opens a transaction, calls a third-party payment API that hangs for 90 seconds, then tries to commit. Postgres kills the connection with "FATAL: terminating connection due to idle-in-transaction timeout" and the row locks on the orders table are held until the connection drops, blocking other checkouts. The team initially raises idle\_in\_transaction\_session\_timeout to five minutes, but the backlog of blocked checkouts just grows. The real fix is to complete the payment call outside any database transaction, then open a transaction only to record the result. A server-side timeout of 30 seconds catches any remaining mistakes. Locks are released quickly and the database stops becoming a queue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-26T04:37:59.746897+00:00— report_created — created