New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graceful shutdown for persistent connections #3169
Comments
Hi @zhu-he , I'm using version 4.5.1 of Actix-web, and when I do
Not sure which version you are using, maybe the maintainers did add this on the later version |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When an
actix-web
server receives a SIGTERM signal, it will stop accepting new connections and wait for all active connections to close. After the shutdown timeout configured byHttpServer::shutdown_timeout
, the server will force close all active connections.In our case, we have several servers behind a layer 4 load balancer. When we want to deploy a new version of our service, we will perform a rolling update. We will stop one old server, deploy the new version of the service, and start the new server. Before the old server is stopped, the load balancer will stop making new connections to the old server. However, the old server will still have some persistent connections. If some request is received before the old server is stopped, but not finished before the shutdown timeout, the client will receive a
connection reset by peer
error.After some research, we found that other web frameworks have a more graceful shutdown strategy. For HTTP/1.1, the server will add a
Connection: close
header to all subsequent responses. For HTTP/2, the server will send aGOAWAY
frame to the client. This will allow the client to close the connection gracefully.For example, in the
hyper
crate, the above strategy is implemented in the code. Allhyper
-based web frameworks, such asaxum
, can benefit from this graceful shutdown strategy.We have tried to implement this graceful shutdown strategy in
actix-web
using middleware. However, some difficulties are encountered. For example, the middleware cannot access the shutdown signal, but luckily signals are the only shutdown condition in our case, and we can directly watch them. Another difficulty is that the middleware can only solve the problem in HTTP/1.1, but not in HTTP/2, as the middleware cannot access the underlying connection.We hope that
actix-web
can implement this graceful shutdown strategy. This will makeactix-web
more suitable for production environments.The text was updated successfully, but these errors were encountered: