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

Support graceful shutdown #33

Open
alexcrichton opened this issue Sep 14, 2016 · 6 comments
Open

Support graceful shutdown #33

alexcrichton opened this issue Sep 14, 2016 · 6 comments

Comments

@alexcrichton
Copy link
Contributor

Right now there's no way to gracefully shut down a Core. There's no API for learning how many tasks are still running or receiving a notification when they're all done. Some more discussion can be found on #16.

The current proposal is to add some form of future which receives a notification when there are no tasks on the event loop any more. This would allow building up a "graceful shutdown". My personal preference would be:

impl Handle {
    pub fn poll_shutdown(&mut self) -> Async<()> {
        // ...
    }
}

This function would return Ready if the core has 0 tasks running on it, or NotReady if there are tasks running. If NotReady is returned, then the current task is scheduled to receive a notification when there are 0 tasks running.

@ishitatsuyuki
Copy link

Please, somehow work on this. I'm building a stateful server and I have to properly shutdown to make data consistent.

About the design, I think an easier way is preferred, such as Loop::wait_shutdown().

@ishitatsuyuki
Copy link

I recently came up with another idea: removing the root of evil, spawn(). It's basically an anti-pattern leading to execution out of control. The termination, should be done with future chaining and probably select() instead.

By the way, this disables us from spawning something in Drop, but socket close operation should be explicit from my perspective. I'm leaving that discussion separated.

@Michael-F-Bryan
Copy link

Has there been any update on this? I'm also working on a server program and it'd be nice to gracefully shut down to the server on some sort of signal.

@alexcrichton
Copy link
Contributor Author

@Michael-F-Bryan no there has not been progress on this in this crate, it will likely be closed as "no longer valid" once tokio-rs/tokio-rfcs#3 is implemented

@Michael-F-Bryan
Copy link

Would you be able to elaborate on that a bit? Looking at the async/await example on that RFC it sounds like the user is given control, and therefore able to stop a server whenever they want, compared to the current model where a reactor is in charge and all we can do is schedule callbacks... Did I understand that correctly?

@alexcrichton
Copy link
Contributor Author

The main thrust of the RFC is to separate out the executor from the reactor itself, and the executor separated out has methods of being shut down and gracefully waiting for shutdown. In general each application has its own definition of graceful shutdown, so it would then be up to you to define the future for shutting down a server.

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

No branches or pull requests

3 participants