Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Handle ctrl+c to gracefully shutdown the server(s) #1613
Handle ctrl+c to gracefully shutdown the server(s) #1613
Changes from 2 commits
6adb7fa
bd98911
2efb8d8
686f274
3cd7aef
e3d2027
078c92d
b71d15a
0b6f312
d295ed9
9a15af3
236a4f0
96f7556
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this channel for the ws server? Doesn't calling
self.web_server_join_handle.abort()
(as we do indrop
) already work?That's one of the advantages of async tasks in general: they are easy to cancel (just drop their handles).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. I could try ripping out the channel again from both servers and go with
abort
. Wonder if that is the same really as the shutdown I'm doing now.I'd suggest not going there and unify as suggested above by using
shutdown_tx
onDrop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropping a handle does not cancel a task though, one needs to call
abort
on it explicitly? (only found this old thread where that decision was made, maybe has changed since then tokio-rs/tokio#1830 (comment))Also do all tasks implement proper abort? The channel setup here follows tokio's recommendation on how to deal with ctrl+c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought
abort
would work on anyasync
task, since it simply stops the future from being polled. I don't understand why tokio would recommend something else.Where is this recommendation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://tokio.rs/tokio/topics/shutdown
Maybe this is a bit too much out of context we're dealing with more specific tasks after all. Furthermore, most of this does boil down to an
abort
I reckon. The reason I ended up here was not exhaustive research and consideration of what we have, but rather seeing that example and going with it, discovering stuff in the process.That said, I'm actually quite happy with this solution here since it gives us a single super easy entry point for signaling shut down which also makes it easy to work with hyper's
with_graceful_shutdown