swift-server / swift-service-lifecycle

Cleanly startup and shutdown server application, freeing resources in order before exiting.
https://swiftpackageindex.com/swift-server/swift-service-lifecycle/documentation/servicelifecycle
Apache License 2.0
385 stars 37 forks source link

Fix logic issues during graceful shutdown #171

Closed FranzBusch closed 7 months ago

FranzBusch commented 7 months ago

Motivation

This should fix the remaining issues raised in https://github.com/swift-server/swift-service-lifecycle/pull/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.