Repository navigation
core: synchronize Stop with concurrent config reloads - #8038
Merged
Merged
Conversation
Signed-off-by: hendrixx-cnc <tjhendrx@icloud.com>
steadytao
enabled auto-merge (squash)
September 19, 2026 15:56
Contributor
Author
|
Thanks for the quick review and merge @steadytao |
Member
|
No worries. Thank you for the PR. |
This was referenced Sep 30, 2026
SillyZir
added a commit
to SillyZir/caddy
that referenced
this pull request
Oct 8, 2026
caddyserver#8038 moved the clearing of currentCtx ahead of unsyncedStop, so during shutdown Cleanup no longer finds a serving TLS app: it takes its teardown path and stops the published cache itself. The two tests that prove a cache is still being maintained do so by stopping it, and had therefore already consumed it, so shutdown stopped it a second time and panicked on the closed channel. Detach a consumed cache from both the app that owns it and the package-level publication before stopping it, so neither teardown path has anything of its own left to stop. That also makes the per-test consumed bookkeeping redundant, since shutdown now zeroes the published cache on its own. Only the tests change. Both negative controls were re-run and still fail as they should: reintroducing publish-and-stop inside Provision fails the liveness assertion, and dropping Cleanup's ownCache != publishedCache guard makes shutdown double-stop the published cache.
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.
What does this PR do?
Synchronizes
Stop()with concurrent configuration reloads and changes to prevent orphaning active server contexts.Problem
In
caddy.go,Stop()previously readcurrentCtxundercurrentCtxMu.RLock()prior to acquiringrawCfgMu.Lock():If a concurrent reload (such as
caddy.Load()or an admin API config change) executes between releasingcurrentCtxMuand acquiringrawCfgMu:Stop()snapshots the old context.rawCfgMu.Lock(), transitionscurrentCtxto the new configuration, and stops the old context.Stop()then acquiresrawCfgMu.Lock(), callsunsyncedStop(ctx)on the already-stopped old context, and proceeds to wipecurrentCtx = Context{}.currentCtxis wiped, orphaning them without a mechanism to shut them down.Solution
Acquire
rawCfgMu.Lock()at the start ofStop(), and snapshot and resetcurrentCtx = Context{}atomically undercurrentCtxMu.Lock(). Because all reloads and config mutations serialize onrawCfgMu, this guarantees thatStop()operates on the true active context and cannot interleave destructively with reloads.Verification
go test -v .(all tests passed).go build ./....Assistance Disclosure
I authored and tested this fix, using AI assistance for concurrency analysis and verification.