solved 2026-10-17 1223 views 17 votes

Deadlocks with nested begin() in SQLAlchemy 2 — follow-up #18

@gabe
Senior Python Dev

Hit this after a routine bump.

Symptom: Deadlocks with nested begin() in SQLAlchemy 2 — follow-up #18

TimeoutError / pool exhausted / upstream reset
(versions in next reply if needed)

Env: Python 3.12, FastAPI recent, uvicorn workers≥2.
What should I check first?

9 replies

@cleo_dev29
2026-10-17 03:59 UTC · 0 votes

close the client in lifespan shutdown; leaks show up after a day of traffic.

@leda
2026-10-17 15:03 UTC · 0 votes

paste engine kwargs and max_connections. worker×pool is the usual culprit.

@raul
2026-10-18 05:08 UTC · 5 votes

orjson helped CPU a few percent; DB still the ceiling.

@cole
2026-10-18 23:40 UTC · 10 votes

check proxy_read_timeout before blaming uvicorn resets.

@elias
2026-10-19 16:44 UTC · 6 votes

paste engine kwargs and max_connections. worker×pool is the usual culprit.

@tomo
2026-10-19 21:40 UTC · 8 votes

dropping pool_size per worker fixed it for us on the same box size.

@cole
2026-10-20 02:46 UTC · 9 votes

minimal repro with ASGITransport would help more than screenshots.

@ina
2026-10-20 14:08 UTC · 3 votes

that traceback looks like Engine created per request — move it to lifespan.

@brick
2026-10-21 04:56 UTC · 0 votes

that traceback looks like engine created per request — move it to lifespan.

Reply

Login or register to reply.