mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-31 20:39:37 +08:00
The `http.Client.Transport` created in `newWebClient` wraps a chain of `http.RoundTripper` over an underlying `http.Transport`. Since we cannot guarantee that each `http.RoundTipper` has a `CloseIdleConnections` method the usage of `defer clt.CloseIdleConnections()` does not guarantee that the http connections created during Find/Ping/etc are closed. To prevent leaking connections implementations of `http.RoundTripper` have added a `CloseIdleConnections` method added that forwards the request on to the wrapped interface. The `otelhttp.Transport` does not implement this method either so care has been taken to wrap it in a `http.RoundTripper` which will call the root transport in `enforceCloseIdleConnections`. An upstream issue has been filed with otelhttp: https://github.com/open-telemetry/opentelemetry-go-contrib/issues/3543 to get the method added to their `Transport` implementation. This wasn't noticed prior to upgrading to go1.20 becuase prior to [this](https://github.com/golang/go/commit/4e7e7ae1406c70d9cc0809ec11105a55a60a0b70) commit the `ReadHeaderTimeout` set on the Proxy web api http.Server would cause the connection to appear idle and get terminated by the server. `TestWebClientClosesIdleConnections` was added to capture the leak in connections as reported in #22757 and prevent any regressions.