# "terminating connection due to idle-in-transaction timeout"

## Symptom
`terminating connection due to idle-in-transaction timeout` kills connections mid-work.

## Cause
The application opened a transaction (`BEGIN`), then sat idle inside it: waiting on an HTTP call, user input, a queue, or just slow code between statements. Neon ends transactions that sit idle too long. This is an application bug the database is correctly punishing, and it is worse on the pooler, where the held backend blocks a pool slot.

## Confirm
1. Find the pattern: `BEGIN` ... (non-DB work) ... `COMMIT`. Logging transaction duration exposes it.
2. Check for ORM "transaction per request" middleware that wraps slow handlers.

## Fix
- Do all non-database work before `BEGIN` or after `COMMIT`; keep transactions to SQL only.
- Set a client-side statement/idle timeout so the app fails fast instead of hanging.
- Break big transactions into smaller ones where semantics allow.

## Verify
No idle-in-transaction terminations under the same workload; transaction durations drop to milliseconds.