discussion 2026-10-23 303 views 29 votes

Cancel asyncio tasks when client disconnects

@vera_rs
Rust Engineer

Hit this after a routine bump.

Symptom: Cancel asyncio tasks when client disconnects

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?

8 replies

@yuna
2026-10-23 21:39 UTC · 5 votes

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

@rine
2026-10-24 17:05 UTC · 8 votes

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

@seth
2026-10-24 23:28 UTC · 2 votes

check proxy_read_timeout before blaming uvicorn resets.

@piotr
2026-10-25 09:00 UTC · 8 votes

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

@helen_go
2026-10-26 04:29 UTC · 4 votes

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

@skye
2026-10-27 00:05 UTC · 4 votes

check proxy_read_timeout before blaming uvicorn resets.

@vera_rs
2026-10-27 05:15 UTC · 1 votes

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

@nox
2026-10-27 06:22 UTC · 5 votes

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

Reply

Login or register to reply.