Skip to content
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

server: fix http graceful shutdown #1090

Merged
merged 11 commits into from
Apr 21, 2023
Merged

Conversation

niklasad1
Copy link
Member

@niklasad1 niklasad1 commented Apr 20, 2023

Close #1089

@niklasad1 niklasad1 requested a review from a team as a code owner April 20, 2023 23:02
server/src/server.rs Outdated Show resolved Hide resolved
Either::Left((conn, _)) => conn,
Either::Right((_, mut conn)) => {
Pin::new(&mut conn).graceful_shutdown();
conn.await
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the fix, we need to await for the conn future anyway not just call graceful_shutdown my bad

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting! (I found https://docs.rs/hyper/latest/hyper/server/conn/struct.Connection.html#method.graceful_shutdown more useful)

Might be worth a comment next to these lines to note that since it's a slightly odd API?

Comment on lines 1272 to 1273
// The pending calls should be answered before shutdown.
assert_eq!(res.await.unwrap(), 10);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So If I understand right, the core of this test is that it makes some requests to the server which will take time to respond, and then it asks to stop the server (after all calls have definitely made it to the server but before they will have resolved) and all calls should resolve before the server stops?

Sounds good to me offhand! I assume that without your fix above this fails?

I wonder whether some comment might make it easier to understand the aim, like:

/// - Make 10 calls to the server.
/// - Once they have all reached the server but before they have responded, stop the server.
/// - All calls should be responded to before the server shuts down.

Out of interest what happens if, while it's shutting down (ie while waiting for calls to be responded to), you make some new calls? I'd expect any new calls to to rejected or something, but would they slow down the shutting down process?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did one call after the server.stopped returned to ensure that the server is closed and doesn't accept new connections/calls

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah but what if new calls come in after you call handle.stop() but before handle.stopped().await; finishes?

Eg if the server is quite busy and new connections keep coming in; will it still shutdown?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not tested here indeed but I think it should be possible to add

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me offhand! I assume that without your fix above this fails?

Yes, it fails without my fix

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not tested here indeed but I think it should be possible to add

It'd be good to check this somehow I think just to make sure that continuing new connections won't stop the server from ever shutting down :)

Yes, it fails without my fix

Woop!

Copy link
Collaborator

@jsdw jsdw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small suggestion re the test but looks good to me!

server/src/server.rs Outdated Show resolved Hide resolved
server/src/server.rs Outdated Show resolved Hide resolved
server/src/server.rs Outdated Show resolved Hide resolved
@niklasad1 niklasad1 merged commit a0e0170 into master Apr 21, 2023
@niklasad1 niklasad1 deleted the na-fix-http-graceful-shutdown branch April 21, 2023 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http server: graceful shutdown doesn't work
3 participants