solved 2026-11-07 930 views 28 votes

SQLAlchemy AsyncSession inside BackgroundTasks? — follow-up #2

@cleo_dev29
Junior Python Dev

Hit this after a routine bump.

Symptom: SQLAlchemy AsyncSession inside BackgroundTasks? — follow-up #2

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

@vera_rs
2026-11-07 16:17 UTC · 10 votes

measure with keep-alive on; cold connects inflate p99.

@leo_cache
2026-11-08 05:04 UTC · 4 votes

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

@nox
2026-11-08 10:37 UTC · 10 votes

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

@tomo
2026-11-09 02:29 UTC · 4 votes

check proxy_read_timeout before blaming uvicorn resets.

@sana
2026-11-09 15:29 UTC · 8 votes

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

@gabe
2026-11-09 23:00 UTC · 9 votes

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

@tomo
2026-11-10 11:06 UTC · 4 votes

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

@leda
2026-11-11 02:37 UTC · 2 votes

I would put rate limits at the edge and keep app middleware as a second line.

@leda
2026-11-11 11:20 UTC · 3 votes

measure with keep-alive on; cold connects inflate p99.

Reply

Login or register to reply.