axum-server
axum-server copied to clipboard
fix: propagate graceful shutdown to inner hyper connection
The hyper v1 migration PR (#93) accidentally (?) removed the call to serve_future.graceful_shutdown(), which prevents the server from shutting down until all client connections close on their own (or we hit the hard shutdown timeout).
In practice, this meant we always hit the hard shutdown timeout, since most clients use connection pools with connection keepalive.
With this change, graceful shutdown will now correctly stop handling any new requests after it's triggered, while letting existing requests complete (within the timeout of course).
The fix itself is just one line:
let serve_future = builder.serve_connection_with_upgrades(io, service);
tokio::pin!(serve_future);
tokio::select! {
biased;
_ = watcher.wait_graceful_shutdown() => {
+ serve_future.as_mut().graceful_shutdown();
tokio::select! {
biased;
_ = watcher.wait_shutdown() => (),
_ = &mut serve_future => (),
}
}
_ = watcher.wait_shutdown() => (),
_ = &mut serve_future => (),
}
The bulk of the PR is fixing the graceful shutdown tests.
Fixes #114