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
Adding graceful shutdown to server #1977
Conversation
@djc @bluejekyll this is a WIP, but I wanted to send it out to get early feedback. |
@djc regarding your #1976 (comment), looks like we don't currently depend on hyper. Not sure if it would be acceptable to bring that in as a general dependency. Thoughts? |
I did not mean bringing in hyper as a dependency, merely copying the way it implements graceful shutdown (which seems like it might be lighter-weight than the linkerd stuff that you copied)? |
@djc I reworked this based on your comments regarding hyper. So far, I've only implemented UDP so we can see what it looks like. PTAL. |
This seems to add a whole bunch of abstraction on top of what's there now just to add graceful shutdown. Instead, I think we should plug graceful shutdown functionality into the existing abstractions. |
My first pass with the linkerd drain crate was just this. However, after looking into a more generic approach (as is done with hyper's Server API), I ran problems with the current structure of Ideally, when we start each server loop we would pass in a graceful shutdown future that can be used in A few paths forward that come to mind:
Note that because the future is internally being passed into
I'm definitlely not a rust expert so there may better ways around some of the issues I was encountering. Although at the end of the day, the I'm definitely open to suggestions. @djc @bluejekyll thoughts? |
I'm coming to this conversation a little late. Looking briefly, I'm not sure why the new server is necessary? Thinking about how I solve similar problems,I would probably just share an I haven't looked at the code in a lot of detail right now, but based on my memory of it I think this would be possible. Is this something you considered? (I haven't looked at the Hyper implementation mentioned). The Type would be a handle that would be returned by the server, something roughly like: #[derive(Clone)]
struct ServerHandle {
is_shutdown: Arc<AtomicBool>, // if false, then handlers should continue accepting work
}
impl ServerHandle {
/// Tell the server handlers to shutdown
pub fn shutdown(&self) {
is_shutdown.store(true);
}
/// Handler loops would read this every loop iteration, stop if true
pub fn is_shutdown(&self) -> bool {
is_shutdown.load()
}
} The Ok, looking a little more at the ServerFuture type, I think we could add something like the |
@bluejekyll That's fair. The current complexity is due to the fact that it allows the application to use their shutdown hooks directly, similarly to what hyper does. This does introduce a lot of complexity, and I think you're right, ... we don't need it. Will update the PR shortly. |
@bluejekyll @djc I refactored things, PTAL when you get a moment. |
e8635d8
to
499e2c0
Compare
Also, not sure why the build is failing to find |
Probably because tokio's Cargo features aren't depended upon correctly. |
c621369
to
08293c5
Compare
@djc I resolved the issue with finding |
No, you'll need to dig in and figure out what's going on. |
ce21981
to
e7a7604
Compare
@bluejekyll @djc I ended up going back to using linkerd's Additionally, this PR seems to be having issues with code coverage (currently at ~61%). I've updated all uses of |
Ah, yes. I see the issue, needing to wake all the tasks on shutdown, I hadn't really been thinking about that, so thanks for pointing out the complexity here. I guess the question I have, is drain-rs the simplest object type for this? I don't know much about that dependency, but in theory, any future aware channel would work just as well and avoid a new dependency, correct? |
Are you thinking there is something we can leverage from existing dependencies here? Or are you suggesting that we roll our own? AFAICT the |
That sounds plausible to me. |
@bluejekyll @djc I've rebased and also added a small wrapper around the linkerd drain signal, so that we don't expose their API from Also, any thoughts on this?
|
Sure, there's no need to fix up all of the lack of coverage here. |
Thanks for all the explanations, @nmittler, I agree with this usage. I also just took a look at the code, seems reasonable enough to me. On the code coverage, I use that to really understand he risk we might have in regards to changes coming in, not something necessarily required for us to hit. |
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.
Ok, I've reviewed. I think this overall looks good. I don't want to get pedantic on naming, but I'm not sure I would name the local variables drain
but instead something more like shutdown
or something that's a little closer to their usage.
@djc, can you close out some of your conversations if you don't have any open concerns?
Thanks for putting this all together @nmittler , I know this has taken a while, I appreciate you working through all the discussion points and taking the time to see this through.
44522b5
to
bf1f954
Compare
Thanks @bluejekyll. FYI, I just pushed a change to use |
@djc any other comments/concerns before we land this? |
Merging, thanks for getting this done, @nmittler! |
@bluejekyll @djc thank you! |
@bluejekyll what is the cadence for pushing new artifacts? I'd like to switch Istio over to using the graceful shutdown logic when it's available. |
Since we're on alpha's right now, I'd be happy to publish another release today. |
@bluejekyll excellent! Thanks for all your help! |
@nmittler thanks for implementing this! I unfortunately couldn't dedicate more time than creating the issue. |
We shouldn't move ownership on shutdown_gracefully(), that complicates things. |
Please file a new issue or PR with suggestions on what we should do instead and what your use case is (why does this complicate things). |
Fixes #1976.