Skip to content

Is gracefull shutdown possible? #15

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

Open
wmww opened this issue Nov 25, 2020 · 3 comments
Open

Is gracefull shutdown possible? #15

wmww opened this issue Nov 25, 2020 · 3 comments

Comments

@wmww
Copy link

wmww commented Nov 25, 2020

Is there a way to gracefully shut down the rtc_server.recv() loop without waiting for the next packet?

EDIT: I'm currently using futures::future::Abortable to kill it, seems like a better way would be optimal but this is working for now.

@kyren
Copy link
Owner

kyren commented Apr 25, 2021

Right now (with one small commit that I'm adding) it's possible to implement a graceful shutdown on top of the current Server I think. The graceful shutdown paths are a very poorly tested, but I think it would go like this:

  1. Hook up some kind of signal to the futures driving SessionEndpoint and Server::recv and select! on it in both cases.

  2. Once the shutdown signal is received by the future driving the SessionEndpoint, stop creating new sessions (you can drop the SessionEndpoint at this point).

  3. Once the shutdown signal is received by the future driving the Server itself, start a shutdown loop:
    a. For every connected client (via the Server::connected_clients method), call Server::disconnect on it.
    b. Call Server::recv with a short timeout.
    c. Check Server::active_clients to see if any clients are left in any state where they require more processing.
    d. Repeat until some global timeout is reached.

The last step would allow for any new incoming clients to finish establishing and then be completely closed, and I think there are no weird race conditions there.

This requires a new method Server::active_clients to get the count of clients in any state other than completely shut down, which I am currently adding.

@kyren
Copy link
Owner

kyren commented Apr 25, 2021

I would accept a PR to make this a method on Server as well, if anyone is interested, but I actually think that before this happens the entire graceful shutdown procedure needs to be looked at much more closely and improved. I don't think it currently works in the presence of packet loss and I'm not entirely sure how to make it work properly at all using openssl's API.

@wmww
Copy link
Author

wmww commented Apr 26, 2021

Thanks! I will give implementing this a shot at some point, when I get back to the project that needs it.

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

2 participants