Skip to content

test(agent): retry once a GET whose idle connection Caddy closed during the switch - #437

Merged
samuelmbabhazi merged 3 commits into
mainfrom
fix/real-caddy-keepalive
Nov 23, 2026
Merged

samuelmbabhazi merged 3 commits into
mainfrom
fix/real-caddy-keepalive

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

TestRealCaddySwitchesUnderLoadWithoutAFailedRequest failed once in about 30 CI runs, on #427, which does not touch the agent: 3 of 8,612 requests failed during the switch.

What the failure was

  • The errors were on the client's connection to Caddy: write: connection reset by peer, read: connection reset by peer, EOF. An upstream that could not be reached would have given a 502 instead.
  • Caddy's log shows two configuration loads, 1 ms apart, at the switch (the route, then its plain-HTTP hosts). At each load, Caddy stops the previous server:
    • it lets active requests finish, since the default grace period has no end;
    • it closes idle keep-alive connections at once.
  • A client that sends a request on an idle connection at that instant gets a reset. Its request was not served. This is the usual race of HTTP/1.1 keep-alive. RFC 9112, section 9.3.1, lets a client send an idempotent request again on a new connection, and browsers do.

Trying to reproduce it

  • Locally, against the Caddy that compose.yml pins: 6 runs of the test, then a stress of 20 switches under 32 clients (16,949 requests). Not one failure.
  • On the CI runner (the first commit of this branch, since removed): 40 switches under 32 clients, 33,329 requests. Not one failure either.
  • So the race is rare, and I could not catch it to prove that those 3 failures were on reused idle connections. The change below is built so that a later failure says it.

What changed

  • load traces each request's connection (httptrace), and knows whether it was a reused idle one.
  • Only a failed request on a reused idle connection is sent again, once. It is counted, and the test logs the count.
  • Every other failure still fails the test: a reset on a new connection, an error status, a second failure after the retry, or a wrong upstream. Its message now says whether the connection was a reused idle one, so that the next failure, if any, tells the two cases apart.

Follow-up, not in this pull request

ApplyRoute changes Caddy's configuration twice per switch: the route, then the plain hosts. One load per switch would halve the moments at which idle connections are closed.

How it was tested

  • go vet -tags integration and golangci-lint: 0 issues.
  • The real Docker and Caddy job runs on this pull request.

Security considerations

Test only.

… connection

Temporary stress run included, to classify the rare failures of the switch test on the CI runner.

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between af21481 and 67c1891.

Files selected for processing: 1

  • agent/internal/actions/real_caddy_test.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

…ion during the switch

Caddy closes idle keep-alive connections at each configuration change. A request sent on one at that instant fails unserved, and HTTP lets an idempotent request be sent again (RFC 9112, 9.3.1). The switch test now retries that one case, counts it, and still fails on any other error. Each failure says whether its connection was a reused idle one.

Signed-off-by: samuel mbabhazi <[email protected]>
@samuelmbabhazi samuelmbabhazi changed the title test(agent): classify the rare failures of the route switch under load test(agent): retry once a GET whose idle connection Caddy closed during the switch Nov 23, 2026
@samuelmbabhazi
samuelmbabhazi marked this pull request as ready for review November 23, 2026 14:35
@samuelmbabhazi
samuelmbabhazi merged commit 3c8a5dd into main Nov 23, 2026
25 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/real-caddy-keepalive branch November 23, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant