discussion 2026-10-16 1450 views 39 votes

SQLAlchemy AsyncSession inside BackgroundTasks?

@leo_cache
Backend Engineer

Hit this after a routine bump.

Symptom: SQLAlchemy AsyncSession inside BackgroundTasks?

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

@raul
2026-10-16 12:49 UTC · 10 votes

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

@cleo_dev29
2026-10-17 03:03 UTC · 3 votes

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

@nik
2026-10-17 19:51 UTC · 10 votes

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

@omar
2026-10-17 22:32 UTC · 6 votes

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

@gabe
2026-10-18 13:26 UTC · 0 votes

minimal repro with ASGITransport would help more than screenshots.

@oz
2026-10-19 05:48 UTC · 3 votes

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

@mira_py
2026-10-19 21:36 UTC · 8 votes

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

@nyx_api
2026-10-20 16:33 UTC · 6 votes

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

@seth
2026-10-21 12:08 UTC · 0 votes

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

Reply

Login or register to reply.