From 2ee6bdf8379000a043aa258df8d3a1a742ceec65 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 10 Nov 2026 19:08:14 -0700 Subject: [PATCH] reverseproxy: align trailer tests with consumed-stream retry safety Follow up report de1bcf6d-457c-4348-9d4e-5eeb41cc120b. Expect one transport attempt for consumed partial streams while keeping unread dial retries and fully buffered trailer replay covered. Validated the entire reverseproxy package with offline race-short tests in a loopback-only network namespace. Code written by GitHub Copilot (GPT-6.1 Sol, Claude Opus 5.5); reviewed by mholt. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../reverseproxy/request_trailers_test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/caddyhttp/reverseproxy/request_trailers_test.go b/modules/caddyhttp/reverseproxy/request_trailers_test.go index f3349f880..14f889bc7 100644 --- a/modules/caddyhttp/reverseproxy/request_trailers_test.go +++ b/modules/caddyhttp/reverseproxy/request_trailers_test.go @@ -349,10 +349,7 @@ func TestRequestTrailersRetry(t *testing.T) { return nil, err } if tc.partial { - _, err := io.ReadAll(r.Body) - if err == nil { - t.Error("partially consumed request body became replayable") - } + t.Error("partially consumed request body was retried") return nil, errors.New("consumed body is not replayable") } return transport.RoundTrip(r) @@ -367,8 +364,14 @@ func TestRequestTrailersRetry(t *testing.T) { req = req.WithContext(ctx) rec := httptest.NewRecorder() err := h.ServeHTTP(rec, req, nil) - if attempts != 2 { - t.Fatalf("attempts=%d, want 2", attempts) + wantAttempts := 2 + if tc.partial { + // Consumed streams must stop before another transport attempt; + // unread dial failures and fully buffered bodies remain replayable. + wantAttempts = 1 + } + if attempts != wantAttempts { + t.Fatalf("attempts=%d, want %d", attempts, wantAttempts) } if tc.partial { if err == nil {