Repository navigation
[backport-0.21] core: don't let a late Detach force-kill a service being stopped - #15069
Merged
Merged
Conversation
An explicit graceful Service.stop zeroed the service's bindings but left it running until it exited. A Detach of one of its remaining bindings arriving meanwhile drove bindings to -1 and started its own graceful stop: a second SIGTERM, then a SIGKILL after TerminateGracePeriod (10s). So any service that takes longer than that to shut down cleanly was killed partway through the clean shutdown its caller asked for. In CI this hits nested engines, which can take a while to sync their cache on shutdown; the next engine then wipes its store as uncleanly shut down. Track the stops in flight for each running service under the manager lock: - Detach of a service that is already stopping (bindings 0) is a no-op, so bindings never go negative and repeated Detaches don't start timers. - An explicit graceful stop joins a stop already in flight instead of sending another SIGTERM, and still reports the stop result once the service exits. - A force stop still sends SIGKILL immediately. - If an explicit stop returns before the service exits, e.g. its context is canceled, and no other stop is in flight, the service is stopped as if it were detached, so it isn't left running with no binders. Backported from #14440. On 0.21 a container service's stop doesn't report cleanup failures, so the test that a joined stop reports the stop result uses a stand-in stop error instead of main's container service helpers. Signed-off-by: Erik Sipsma <[email protected]>
tiborvass
approved these changes
Nov 6, 2026
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
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.
Backport to 0.21 of #14440, as one commit.
What this changes for 0.21 users
When a service is stopped gracefully, for example with
Service.stop, and one of its bindings detaches while it is shutting down, that detach starts a second stop: another SIGTERM, then a SIGKILL 10 s later. So a service that takes more than 10 s to shut down cleanly is killed partway through the clean shutdown its caller asked for.In CI this hits nested engines, which can take a while to sync their cache on shutdown. The next engine then wipes its store as uncleanly shut down. On backport-0.21 it is one of the causes of
TestCachePersistence/TestDiskPersistenceAcrossRestart/engine-dev_container_build_survives_restartfailing, as it did on #15040.With this backport, a detach of a service that is already stopping does nothing, and a graceful stop joins a stop already in flight instead of signaling again. A force stop still kills at once, and a service whose stop gives up is still stopped as if it were detached.
Differences from main
The change applied cleanly. One test needed adapting: on main, a container service's stop reports cleanup failures, which 0.21 doesn't have. The test that a joined stop still reports the stop result now uses a stand-in stop error instead of main's container service helpers.
The service tests in
core(TestServices*) pass three times in a row under-raceon this branch.