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

Fixed: #1645 Impossible to shut down server before it has started #1646

Conversation

OskiKervinen-MF
Copy link

Added a new method decommission to Server. This method allows you to shut down the server without caring about if it has already started or not. This avoids the need to wait in a loop for the server thread to be finished starting up before you can safely do operations that could decide to stop it.

Waiting for the server thread to finish starting is convenient with Server::wait_until_ready, but if the server thread performs initializations that could throw exceptions, causing the server to never start up, calling wait_until_ready will hang the program. The only way to guarantee this won't happen in any possible ordering of events is to have an operation that will cause listen_* to exit immediately, whether or not it is called before or after. That is what decommission provides.

Fixes: #1645

Fixes yhirose#1645.

`Server::stop` does nothing if the server is not running.
This can cause a program to hang it it calls stop before
the server processing thread has had time to initialize.
It would make sense for a server that has been stopped
to refuse to start, but that would be backwards incompatible.
Instead, we introduce a new method: `decommission`.
It sets the server object to stop and refuse to start.
This means it does not matter in which order
concurrent threads end up calling `listen` and `decommission`,
the result is always that the listening thread will exit.
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.

It is impossible to shut down the server safely, concurrently and cleanly
2 participants