Repository navigation
httpcaddyfile: give each adaptation its own directive order - #7995
Merged
francislavoie merged 1 commit intoSep 6, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The concurrency fix is well-scoped (per-adaptation state instead of global mutation) and is backed by targeted regression tests; only a minor test maintainability nit was found.
Pull request overview
Fixes a concurrency bug in the HTTP Caddyfile adapter where the order global option could mutate shared process-wide directive ordering, causing subsequent adaptations to fail until restart. The change scopes directive ordering to each adaptation while keeping plugin-registered directive order global and init-only.
Changes:
- Make
orderhandling per-adaptation:parseOptOrdernow works on a local copy and returns the updated order instead of mutating a global slice. - Thread directive order explicitly through
buildSubroute/sortRoutes, and adddirectiveOrderFor(options)to resolve per-adaptation order vs. plugin order. - Clone the adapter
optionsmap inSetupto avoid cross-adaptation leakage and make options-map reuse/concurrent reuse safe; add regression tests for sequential/concurrent adapts and plugin-registered ordering.
File summaries
| File | Description |
|---|---|
| caddyconfig/httpcaddyfile/options.go | Stops mutating global directive order during order option parsing; returns per-adaptation order. |
| caddyconfig/httpcaddyfile/httptype.go | Clones options map per adaptation and removes accumulated order; passes per-adaptation order into subroute building. |
| caddyconfig/httpcaddyfile/directives.go | Clarifies directiveOrder as init-only, adds directiveOrderFor, and updates sorting to accept explicit order. |
| caddyconfig/httpcaddyfile/directives_test.go | Adds tests covering isolation, reuse, error recovery, concurrency, and plugin-registered directive ordering. |
| caddyconfig/httpcaddyfile/builtins.go | Updates route parsing to use the new buildSubroute signature (no sorting when order is nil). |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
faiyazrahmann
force-pushed
the
fix/directive-order-race
branch
from
September 6, 2026 04:35
4fb8212 to
bccf07d
Compare
parseOptOrder wrote to the package level directiveOrder on every adapt, and slices.DeleteFunc edits the slice in place. Since directiveOrder starts out aliasing defaultDirectiveOrder, two adapts at once could drop entries from the baseline for the rest of the process. The order is now kept per adaptation in options[order] and passed into sortRoutes and buildSubroute, so nothing writes to the global while adapting. No lock, and no exported signatures change. Fixes caddyserver#7994
faiyazrahmann
force-pushed
the
fix/directive-order-race
branch
from
September 6, 2026 11:38
bccf07d to
e137cb0
Compare
francislavoie
approved these changes
Sep 6, 2026
This was referenced Sep 30, 2026
jeffyaw
added a commit
to YawLabs/caddy-mcp
that referenced
this pull request
Nov 30, 2026
…ddy 2.11.6 The caddy_adapt description, the README and the code comments said both fixes were unreleased / milestoned v2.11.5. They shipped in 2.11.6; the README's caddy_load entry now names the 2.11.6+ 400 shape. The <= 2.11.4 caveats stay, since they still hold for those versions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #7994.
parseOptOrderwas modifying the globaldirectiveOrderon every adapt. Since it could share the same underlying slice asdefaultDirectiveOrder, concurrent adapts could permanently remove entries from the default order. After that, any adapt would fail until restart, even ones not usingorder.What changed
directiveOrderis now only changed byRegisterDirectiveOrderduring init.parseOptOrderworks with a local copy and returns the order instead of changing a global.sortRoutesandbuildSubroutenow receive the order directly.Setupclones the options map and dropsorderfrom tis untouched and reusing the same map is safe.RegisterDirectiveOrdernow inserts into a cloned slice.No mutexes or exported API changes.
Tests
Added tests for sequential/concurrent adapts, reused options maps, recovery after a bad
order, the original race reproducer, and plugin-registered directive order. All of them fail on master.Disclosure
I used LLM to generate the tests.