Skip to content

reverseproxy: Only retry responses for expressions that use response data - #8168

Merged
steadytao merged 4 commits into
caddyserver:masterfrom
jayhemnani9910:fix-retry-match-request-expressions
Oct 9, 2026
Merged

steadytao merged 4 commits into
caddyserver:masterfrom
jayhemnani9910:fix-retry-match-request-expressions

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

Closes #8166

Since #7569 every lb_retry_match set containing an expression is evaluated against the upstream response. An expression that only tests the request, like {http.request.method} == "POST", matched every successful response, so the request was sent again to the next upstreams and the client got a 502 when retries ran out.

Response retries now apply only to expressions that reference response placeholders ({rp.*}, which the Caddyfile adapts to {http.reverse_proxy.*}). Other expressions are request conditions again, as before v2.11.3. All the examples from #7569 reference {rp.*} and behave as before.

Test: TestRequestOnlyExpressionDoesNotRetryResponses sends a POST through two healthy upstreams with that expression. Without the change it returns a 502 (ContentLength=7 with Body length 0 on the retry); with it the upstream is hit once and the 200 body comes through. go test ./... passes, including the existing retry_match unit and integration tests.

Manual check with the Caddyfile from the issue: v2.11.7 answers the POST with 502 after three upstream hits; with the change it returns the backend's 200 after one hit.

Assistance Disclosure

Claude Code (Claude Opus) helped write this patch and its test. I reviewed every line, and I ran the test before and after the change and the manual check above myself.

…data

Since caddyserver#7569 every lb_retry_match set with an expression is evaluated against
upstream responses. An expression that only tests the request, such as
{http.request.method} == "POST", then matched every successful response:
the request was sent again to the next upstreams and the client got a 502
once retries ran out. Only treat expressions referencing {rp.*} placeholders
as response conditions.
Copilot AI balanced review requested due to automatic review settings October 7, 2026 06:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@francislavoie francislavoie added the bug 🐞 Something isn't working label Oct 8, 2026
@francislavoie francislavoie added this to the v2.12.0 milestone Oct 8, 2026
The expression matcher records the placeholder names its checked CEL
expression reads, so retry_match finds direct ph() calls and ignores
escaped placeholder text in string literals. A placeholder name only
known at evaluation time counts as response data.
Comment thread modules/caddyhttp/celmatcher.go Resolved
Only the header placeholders are matched by prefix now, and both
upstream latency placeholders are listed. MatchExpression.Placeholders
returns a copy, so callers cannot change the provisioned matcher.
@steadytao
steadytao merged commit 7c74563 into caddyserver:master Oct 9, 2026
31 checks passed
This was referenced Nov 3, 2026
NickCao pushed a commit to NickCao/caddy that referenced this pull request Nov 4, 2026
…data (caddyserver#8168)

* reverseproxy: Only retry responses for expressions that use response data

Since caddyserver#7569 every lb_retry_match set with an expression is evaluated against
upstream responses. An expression that only tests the request, such as
{http.request.method} == "POST", then matched every successful response:
the request was sent again to the next upstreams and the client got a 502
once retries ran out. Only treat expressions referencing {rp.*} placeholders
as response conditions.

* reverseproxy: Only count placeholders set from the response as response data

* reverseproxy: Read response placeholders from the checked expression

The expression matcher records the placeholder names its checked CEL
expression reads, so retry_match finds direct ph() calls and ignores
escaped placeholder text in string literals. A placeholder name only
known at evaluation time counts as response data.

* reverseproxy: Match response placeholder names exactly

Only the header placeholders are matched by prefix now, and both
upstream latency placeholders are listed. MatchExpression.Placeholders
returns a copy, so callers cannot change the provisioned matcher.

(cherry picked from commit 7c74563)
@francislavoie francislavoie modified the milestones: v2.12.0, v2.11.8 Nov 4, 2026
@jayhemnani9910
jayhemnani9910 deleted the fix-retry-match-request-expressions branch November 13, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reverseproxy: lb_retry_match with a request-only expression retries successful responses (502 since v2.11.3)

4 participants