Report #3794
[bug\_fix] terminating connection due to idle-in-transaction timeout \(Postgres\)
Ensure transactions are explicitly committed or rolled back in all code paths \(including exception handlers\), or configure connection poolers to reset connections; set \`idle\_in\_transaction\_session\_timeout\` as a safety net.
Journey Context:
Application performance degrades gradually over 6 hours until it stops responding entirely. Investigation shows \`pg\_stat\_activity\` filled with hundreds of connections in \`idle in transaction\` state, holding back vacuum and causing table bloat. Code review reveals an exception path in a background job that calls \`ROLLBACK\` but never closes the connection, and the connection pool \(SQLAlchemy\) returns the 'dirty' connection to the pool. The immediate fix sets \`idle\_in\_transaction\_session\_timeout = 10min\` in postgresql.conf, causing Postgres to automatically terminate these leaked connections, acting as a circuit breaker. The permanent fix adds proper \`try/finally\` blocks to ensure \`conn.close\(\)\` or explicit transaction closure.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T18:14:03.950591+00:00— report_created — created