Skip to content

Commit bd6da95

Browse files
ReneWerner87claude
andcommitted
test(proxy): fix data race and flaky deadline test in v2 CI
Two pre-existing issues in middleware/proxy made v2 CI red under `go test -race` on newer Go versions and Windows: 1. Data race: Test_Proxy_Forward_WithTlsConfig called WithTlsConfig(), which mutates the field client.TLSConfig on the package-global client with no synchronization against fasthttp's concurrent read of that field from parallel proxy tests. Swap the whole global client via WithClient(&fasthttp.Client{TLSConfig: ...}) instead (pointer swap under the existing lock), mirroring the v3 fix. The public WithTlsConfig API is left untouched. 2. Flaky timing: Test_Proxy_DoDeadline_PastDeadline used a 1s DoDeadline deadline equal to app.Test's default 1000ms timeout, so two coincident timers raced. Bump the deadline to 2s so app.Test's timeout fires first deterministically (same approach as v3). Test-only change, no production or API changes. Verified 12/12 green with `-race -shuffle=on`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 493b955 commit bd6da95

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

middleware/proxy/proxy_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ func Test_Proxy_Forward_WithTlsConfig(t *testing.T) {
249249
addr := ln.Addr().String()
250250
clientTLSConf := &tls.Config{InsecureSkipVerify: true} //nolint:gosec // We're in a test func, so this is fine
251251

252-
// disable certificate verification
253-
WithTlsConfig(clientTLSConf)
252+
// disable certificate verification by swapping the whole global client
253+
// (WithTlsConfig mutates the shared client's field and races with parallel proxy tests)
254+
WithClient(&fasthttp.Client{TLSConfig: clientTLSConf})
254255
app.Use(Forward("https://" + addr + "/tlsfwd"))
255256

256257
go func() { utils.AssertEqual(t, nil, app.Listener(ln)) }()
@@ -565,7 +566,9 @@ func Test_Proxy_DoDeadline_PastDeadline(t *testing.T) {
565566

566567
app := fiber.New()
567568
app.Get("/test", func(c *fiber.Ctx) error {
568-
return DoDeadline(c, "http://"+addr, time.Now().Add(time.Second))
569+
// Deadline is longer than app.Test's 1000ms timeout so the test timeout
570+
// deterministically fires first (avoids two coincident 1s timers racing).
571+
return DoDeadline(c, "http://"+addr, time.Now().Add(2*time.Second))
569572
})
570573

571574
_, err1 := app.Test(httptest.NewRequest(fiber.MethodGet, "/test", nil))

0 commit comments

Comments
 (0)