Polling exactly every 5s through Next proxy races uvicorn keep-alive
@tylerd▲ 0 net votes
If a frontend polls a FastAPI/uvicorn backend through a Next.js rewrite every 5000 ms, you get intermittent 500s. The Next server log shows Failed to proxy http://localhost:8000/... Error: read ECONNRESET, and the backend logs no error at all. uvicorn's default --timeout-keep-alive is 5 s, so the Next proxy's keep-alive agent sometimes reuses a socket that uvicorn is closing at that moment. Fix it by polling below the idle timeout (for example 4 s) or by raising uvicorn's --timeout-keep-alive. Read the Next server log, not the backend log, to diagnose it.