Repository navigation
fix(agent): a route change is one Caddy configuration load (closes #438) - #566
Draft
samuelmbabhazi wants to merge 3 commits into
Draft
samuelmbabhazi wants to merge 3 commits into
samuelmbabhazi wants to merge 3 commits into
Conversation
ApplyRoute wrote the route, then the hosts without TLS, and RemoveRoute deleted the route before the removal action took its hosts out: two loads for one change, and each load closes the previous configuration's idle connections, so a client sending on one at that instant gets a reset (#437). Both now change the route and automatic_https.skip in one PATCH of the Shipkeep server, under the read's ETag (If-Match), made again from a new read when Caddy answers 412, at most 3 times. The control plane route repair is one write too. The real Caddy test counts the loads in Caddy's log. Signed-off-by: samuel mbabhazi <[email protected]>
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
…unts loads CI starts Caddy empty: the first route action created the Shipkeep server, a load of its own that the agent makes once at start, then wrote the route. Part of #438. Signed-off-by: samuel mbabhazi <[email protected]>
…load Docker stamps a log line when it reads it, a few milliseconds after Caddy wrote it: the load that created the server could land after the time the count started from. The test now waits until that load is in the log before it starts counting. Part of #438. Signed-off-by: samuel mbabhazi <[email protected]>
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
A route change is now one write of the Shipkeep server to Caddy's admin API, so Caddy loads one configuration for it.
writeServer(agent/internal/caddy) is a new helper that reads/config/apps/http/servers/shipkeepwith its ETag, lets a change rewrite the routes andautomatic_https.skip, and writes the server back in onePATCHwithIf-Match.412, and the write is made again from a new read, at most 3 times.ApplyRoutewrites the route and its hosts without TLS in that single write. Before, it wrote the hosts to remove, the route, then the hosts to add: up to three writes, two of them changing the configuration. A refused write now leaves the previous configuration whole, so the old ordering argument for keeping hosts reachable is no longer needed.RemoveRoute(ctx, id, plainRemove)takes the route's hosts out in the same write. The removal action no longer callsSetPlainHosts, which is gone from theRouterinterface and from the client.EnsureControlPlaneRoutes(the repair of the control plane's routes on a single machine) is one write too: the list in its order, and the control plane's name taken off the skip list.dogoes through a newsend, which carriesIf-Matchand returns the ETag.dolost itsoutparameter, which every remaining caller passed asnil.Why
#438 (found in #437): each configuration load makes Caddy's previous HTTP server close its idle keep-alive connections. A client that sends a request on one of them at that instant gets a reset. Two loads 1 ms apart for one route change doubled those moments, and between the two writes the route and the skip list disagreed.
How it was tested
Against a real Caddy 2.11.9 (the image pinned in
compose.yml, admin on a Unix socket), countingautosaved configlines in its log:EnsureServeron an empty configurationRemoveRoutewith its hostRemoveRouteof a route already goneEnsureControlPlaneRoutesEnsureServersecuring a hand-written route without the Host bound (PATCH /id/…/match), the second the repair's single writeEnsureServerand the repair againThe same Caddy answered
412(If-Match header did not match current config hash) to a write with a stale ETag. That lab test was not committed.Unit tests (
caddy_test.go, with a fake admin that serves the server path with an ETag and checksIf-Match):PATCH /config/apps/http/servers/shipkeep, keep the other route's place and the server's other fields;412succeeds on the next read, and one refused every time fails after 3 attempts without changing anything;go test -race -count=20 ./agent/internal/caddy/, the agent's other packages andgolangci-lint(with and without theintegrationtag) pass.Real Caddy test in CI:
TestRealCaddySwitchesUnderLoadWithoutAFailedRequestnow reads Caddy's log (SHIPKEEP_IT_CADDY_CONTAINER,sk-it-caddyby default). It checks one load for the first route without TLS, one for the switch to v2 under load, and one for the route's removal. I could not run that test locally: it needs the Docker socket, which this machine's sandbox does not expose. The job "Agent against Docker and Caddy" runs it.Security considerations
If-Matchkeeps a write from replacing a configuration it did not read, such as one changed by another writer between the read and the write.Closes #438.