Uvicorn app shuts down automatically - deadlock? #2126
Replies: 3 comments
-
I have the same issue |
Beta Was this translation helpful? Give feedback.
-
Have you solved it? |
Beta Was this translation helpful? Give feedback.
-
We've solved the shut down issue, but not the deadlock issue. For our app success at least, removing "limit max requests" worked:
as this was responsible for the shutdown itself. If the unvicorn app never shuts down, it won't deadlock on shut down. The other portion that may be to blame for our success - continuously poll the websockets:
As it'd turn out, our |
Beta Was this translation helpful? Give feedback.
-
We have a unvicorn app running via the below :
Our uvicorn app hosts a websocket-based FastAPI app. Part of the logic for the app involves looping on an open user connection and continuously polling the backend for new messages to send the user.
With reliable frequency, via the logs we see the uvicorn app shuts itself down:
but we see processes within the uvicorn app continue, and no server shutdown is reached. The processes running are within an async function.
It seems that we are deadlocked - Gunicorn is trying to shut down the worker process (see
relevant Uvicorn FastAPI issue ), but it must wait for the async process to complete before shutting down.
The net result is our Uvicorn server goes into a 502 state and cannot accept new connections, caught between trying to shutdown and waiting for our websocket-connected continuously polling to complete.
Is this relationship between Uvicorn, Gunicorn workers, and closing child processes known (where Gunicorn tries to shut itself down due to default graceful timeout but the process continues, beginning but not completing the uvicorn server shutdown)? Is there a recommendation to manage child processes? How do we prevent uvicorn from shutting itself down?
Beta Was this translation helpful? Give feedback.
All reactions