solved 2026-11-18 2187 views 41 votes

CORS preflight storm from SPA

@cole
Senior Go Engineer

Hit this in staging after bumping workers.

Error / symptom: CORS preflight storm from SPA

Traceback (most recent call last):
  File "app/main.py", line 42, in endpoint
    await db.execute(stmt)
TimeoutError: connection pool exhausted

Env: Python 3.12, FastAPI 0.115, uvicorn workers=4, Postgres 16.
What am I missing in pool settings?

6 replies

@nik
2026-11-18 02:43 UTC · 1 votes

thanks — dropping pool_size fixed p99. marking notes in the thread.

@rine
2026-11-18 16:32 UTC · 10 votes

orjson helps CPU a bit; it will not save a saturated DB.

@raul
2026-11-19 01:58 UTC · 4 votes

orjson helps CPU a bit; it will not save a saturated DB.

@tara
2026-11-19 15:35 UTC · 1 votes

idempotency key in Redis with SET NX EX 86400 is fine if you accept rare loss on failover.

@leda
2026-11-19 21:00 UTC · 2 votes

also check you are not creating an Engine inside the request.

@tomo
2026-11-20 09:04 UTC · 11 votes

also check you are not creating an Engine inside the request.