From 64289c7388cbc0fb1e5a2510746fe579faece0c7 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Wed, 17 Jun 2026 00:22:41 +1000 Subject: [PATCH] test: use httptest server.Client() to isolate transport (#26409) `TestPush/CachesSubscriptionsWithinTTL` could fail with `Post "http://127.0.0.1:XXXXX": net/http: HTTP/1.x transport connection broken: http: CloseIdleConnections called` when a sibling parallel subtest's `httptest.Server.Close()` ran during an in-flight `Dispatch`. `setupPushTestWithOptions` wired the dispatcher to `http.DefaultClient`, so every parallel subtest in `TestPush` shared `http.DefaultTransport`. `httptest.Server.Close()` calls `CloseIdleConnections` on `http.DefaultTransport`, which could break an in-flight request in any other subtest using the same transport. `httptest.Server` already exposes a paired `*http.Client` backed by a transport dedicated to that server (see `net/http/httptest/server.go`). Closing one server only touches `http.DefaultTransport` and its own client's transport, so sibling cleanup can no longer reach into ours. Same flake class and same isolation principle as #25015, #25407, #25430, and #25821. Closes https://github.com/coder/internal/issues/1593 Closes ENG-2926 --- coderd/webpush/webpush_test.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/coderd/webpush/webpush_test.go b/coderd/webpush/webpush_test.go index 8a30214d89..0a8ca17546 100644 --- a/coderd/webpush/webpush_test.go +++ b/coderd/webpush/webpush_test.go @@ -536,9 +536,7 @@ func setupPushTestWithOptions(ctx context.Context, t *testing.T, db database.Sto server := httptest.NewServer(http.HandlerFunc(handlerFunc)) t.Cleanup(server.Close) - // Use an unrestricted HTTP client for tests. The default SSRF-safe - // client rejects loopback addresses, which blocks httptest.Server. - opts = append(opts, webpush.WithHTTPClient(http.DefaultClient)) + opts = append(opts, webpush.WithHTTPClient(server.Client())) manager, err := webpush.New(ctx, &logger, db, "http://example.com", opts...) require.NoError(t, err, "Failed to create webpush manager")