-
Notifications
You must be signed in to change notification settings - Fork 42
Address some race conditions during the graceful shutdown process. #166
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
Closed
tachyonics
wants to merge
1
commit into
swift-server:main
from
tachyonics:sp_address_graceful_shutdown_race_conditions
Closed
Address some race conditions during the graceful shutdown process. #166
tachyonics
wants to merge
1
commit into
swift-server:main
from
tachyonics:sp_address_graceful_shutdown_race_conditions
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Motivation: Address and add tests for the following race conditions- 1. If `.signalSequenceFinished`, `.gracefulShutdownCaught` or `.gracefulShutdownFinished` occur during graceful shutdown, `gracefulShutdownIndex` will be incremented without a service being shutdown causing the process to think the wrong service shutdown signal has been received next, failing shutdown incorrectly. 2. If a signal is caught that isn't a `cancellationSignal`, the same thing will happen as (1). 3. If a service throws out of order (the serviceGroup is waiting for ServiceB to gracefully shutdown but ServiceA throws an error), `gracefulShutdownIndex` will be incremented without waiting for the 'current' service to shutdown. This may incorrectly fail the shutdown process for some `failureTerminationBehavior` modes. 4. The `shutdownGracefully` function cancels the group which may cause the `cancellationCaught` case in the `_run` loop to be triggered next. It is unneccesary to call `cancelGroupAndSpawnTimeoutIfNeeded` here in this case. Modifications: 1. Modified the task group result loop in `shutdownGracefully` to only increment the service iterator when the service being waited on has been confirmed as shut down. 2. Track out-of-order service shutdowns using a mutable `runningServices` array. 3. Add debug logs to signals that were previously silently consumed. 4. Add a mechanism for injecting task group results for testing (if there is a better mechanism, let me know). 5. Added unit tests to verify the race conditions addressed. Result: As verified by the added unit tests, the race conditions will be handled as expected.
FranzBusch
added a commit
that referenced
this pull request
Jan 26, 2024
# Motivation This should fix the remaining issues raised in #166. The problem here was that if a service finished/threw out of order then we were wrongly treating this as if the service that we are currently shutting down finished. # Modification This PR ensures that we use the same `services` array during the graceful shutdown to nil out services that have finished. This way we correctly keep track of any service that finished. Additionally, there was a separate bug where we started to shutdown the next service to early if another service threw and had the termination behaviour of `shutdownGracefully`. # Result No more incorrect shutdown orderings.
FranzBusch
added a commit
that referenced
this pull request
Jan 26, 2024
# Motivation This should fix the remaining issues raised in #166. The problem here was that if a service finished/threw out of order then we were wrongly treating this as if the service that we are currently shutting down finished. # Modification This PR ensures that we use the same `services` array during the graceful shutdown to nil out services that have finished. This way we correctly keep track of any service that finished. Additionally, there was a separate bug where we started to shutdown the next service to early if another service threw and had the termination behaviour of `shutdownGracefully`. # Result No more incorrect shutdown orderings.
FranzBusch
added a commit
that referenced
this pull request
Jan 26, 2024
# Motivation This should fix the remaining issues raised in #166. The problem here was that if a service finished/threw out of order then we were wrongly treating this as if the service that we are currently shutting down finished. # Modification This PR ensures that we use the same `services` array during the graceful shutdown to nil out services that have finished. This way we correctly keep track of any service that finished. Additionally, there was a separate bug where we started to shutdown the next service to early if another service threw and had the termination behaviour of `shutdownGracefully`. # Result No more incorrect shutdown orderings.
FranzBusch
added a commit
that referenced
this pull request
Jan 26, 2024
* Fix logic issues during graceful shutdown # Motivation This should fix the remaining issues raised in #166. The problem here was that if a service finished/threw out of order then we were wrongly treating this as if the service that we are currently shutting down finished. # Modification This PR ensures that we use the same `services` array during the graceful shutdown to nil out services that have finished. This way we correctly keep track of any service that finished. Additionally, there was a separate bug where we started to shutdown the next service to early if another service threw and had the termination behaviour of `shutdownGracefully`. # Result No more incorrect shutdown orderings. * Fix one more race condition
@tachyonics closing this since I think all the problems that you listed here have been fixed on the latest release. Please feel free to reopen if you think they are not! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation:
Address and add tests for the following race conditions-
.signalSequenceFinished
,.gracefulShutdownCaught
or.gracefulShutdownFinished
occur during graceful shutdown,gracefulShutdownIndex
will be incremented without a service being shutdown causing the process to think the wrong service shutdown signal has been received next, failing shutdown incorrectly.cancellationSignal
, the same thing will happen as (1).gracefulShutdownIndex
will be incremented without waiting for the 'current' service to shutdown. This may incorrectly fail the shutdown process for somefailureTerminationBehavior
modes.shutdownGracefully
function cancels the group which may cause thecancellationCaught
case in the_run
loop to be triggered next. It is unneccesary to callcancelGroupAndSpawnTimeoutIfNeeded
here in this case.Modifications:
shutdownGracefully
to only increment the service iterator when the service being waited on has been confirmed as shut down.runningServices
array.Result:
As verified by the added unit tests, the race conditions will be handled as expected.