Closed tachyonics closed 8 months ago
I landed both https://github.com/swift-server/swift-service-lifecycle/pull/171 and https://github.com/swift-server/swift-service-lifecycle/pull/170. Those two should fix all the issues that you have identified here from what I can see. I also brought over your unit tests that weren't injecting a stream since I want to avoid introducing test code into the implementation.
@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!
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.