Uvicorn Graceful Shutdown within kubernetes ecosystem #2257
Replies: 5 comments 8 replies
-
Is there a way to create a MRE? |
Beta Was this translation helpful? Give feedback.
-
Couldn't you run the uvicorn server so that it will wait for a few seconds before acting on the shutdown command? Something like trapping the signal and then waiting before propagating it. |
Beta Was this translation helpful? Give feedback.
-
Hi. I'm also using uvicorn in a K8S context. I could have done that with a single server, of course, but i didn't want to expose my metrics and probes to everyone. Just my 2 cents |
Beta Was this translation helpful? Give feedback.
-
You can use a |
Beta Was this translation helpful? Give feedback.
-
I'm struggling with the same issue and have forked and implemented the sleep-timer before the shutdown https://github.com/Jakobhenningjensen/uvicorn I'm trying to make a PR but I can't really make a unittest for it to work. I can see that we are not the only one who are having that issue i.e if we somehow can make the PR and upvote it enough, we could maybe get it merged? |
Beta Was this translation helpful? Give feedback.
-
Context
Hello, our team is currently using Uvicorn and we are experiencing issues with graceful shutdown. During a graceful shutdown, Uvicorn stops accepting new requests while finishing up any in-progress requests. However, we are dealing with a situation where our Application Load Balancer (ALB) is still sending traffic to the server for a short period of time after receiving the SIGTERM signal. Due to which, service will encounter connection refused error. In order to handle this, we need to keep the port open for a few extra seconds in order to receive these remaining requests for certain period of time.
One possible way to handle this could be to put sleep in shutdown function of Server Class.
However, this is currently not possible to be configured.
We would appreciate insights from the community on how to handle this issue.
We are using
Beta Was this translation helpful? Give feedback.
All reactions