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

Add non-exiting methods and implement SIGHUP reload #405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

samurai00
Copy link
Contributor

Hey team! I've tried to make a few small tweaks to our server to hopefully improve its flexibility and add some reload functionality. Here's what's new:

  • Added pub fn try_bootstrap(&mut self) -> Result<bool> that doesn't call exit
  • Refactored pub fn bootstrap(&mut self) to use the new try_bootstrap method
  • Added pub fn run_server(mut self, enable_daemon: bool) -> Result<bool> that doesn't call exit
  • Kept pub fn run_forever(mut self) -> ! the same, but now it calls run_server under the hood
  • Implemented SIGHUP catching for reloading
  • Added an example server_reload to show how to reload within a tokio runtime

Related issues:

@eaufavor
Copy link
Member

I think it is nice to break down the functions so that it is more flexible.

On the other hand, the reload in the example has a downtime (the old service shuts down before the new service starts). Do you have a plan to address that?

To me, the way of graceful reload is the following
when the reload signal arrives:

  1. start the new service and wait for the listeners to be passed to it
  2. signal the old service to gracefully exit
  3. wait for grace_period_seconds before fully stopping/killing the old service

The current run_server() does 2) + 3) before returning for the example to do 1). So there is a window that the service appear to be offline.

@samurai00
Copy link
Contributor Author

I agree that the new service should be started before shutting down the old one, and I thought I had attempted to do this in the example. After conducting some simple tests, it seemed to work as expected.

However, more thorough testing might be necessary to ensure everything is functioning correctly. I'll conduct some additional tests to verify this.

@johnhurt johnhurt self-assigned this Oct 4, 2024
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.

3 participants