From 13f5cc787248e6d9fac9e6ebe976c218fac54a2b Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Wed, 25 Nov 2026 00:27:35 +0100 Subject: [PATCH] fix(coderd/telemetry): give the reporter its own HTTP transport (#32160) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `high`_ --- coderd/telemetry/telemetry.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/coderd/telemetry/telemetry.go b/coderd/telemetry/telemetry.go index c03a4b9455b..3ceae358b46 100644 --- a/coderd/telemetry/telemetry.go +++ b/coderd/telemetry/telemetry.go @@ -106,6 +106,13 @@ func New(options Options) (Reporter, error) { startedAt: dbtime.Time(options.Clock.Now()).UTC(), client: &http.Client{}, } + // Give the client its own connection pool. On http.DefaultTransport the pool + // is shared with the whole process, and any call to its CloseIdleConnections + // (httptest.Server.Close makes one) can fail a request while net/http hands + // it a response that has no body. + if transport, ok := http.DefaultTransport.(*http.Transport); ok { + reporter.client.Transport = transport.Clone() + } go reporter.runSnapshotter() return reporter, nil } @@ -192,6 +199,9 @@ func (r *remoteReporter) Close() { r.reportWithDeployment() } r.closeFunc() + // Only this reporter uses the pool, and the canceled context stops any + // later request from adding a connection to it. + r.client.CloseIdleConnections() } func (r *remoteReporter) isClosed() bool {