## TL;DR

For "terminating connection due to idle-in-transaction timeout": check for ORM "transaction per request" middleware that wraps slow handlers. 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.

```text
terminating connection due to idle-in-transaction timeout
```

## Steps

1. 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.

2. - 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.

## When to use

You are seeing this: terminating connection due to idle-in-transaction timeout kills connections mid-work. Use this skill when you run into ""terminating connection due to idle-in-transaction timeout": fix the app".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

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.
