stop using the default, global HTTP client to avoid `CloseIdleConnections` flakes
- Dominant language
- No language data
- Stars
- 3
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Some places in coder/coder, [like this](https://github.com/coder/coder/blob/29da25c3964dfb3f1c934e368be8ce65ac302866/coderd/telemetry/telemetry.go#L353), use the default, global HTTP client:
```go
resp, err := http.DefaultClient.Do(req)
if err != nil {
return xerrors.Errorf("perform request: %w", err)
}
```
This causes flakes in our tests with the message `net/http: HTTP/1.x transport connection broken: http: CloseIdleConnections called`:
```
error= perform request:
github.com/coder/coder/v2/coderd/telemetry.(*remoteReporter).deployment
/Users/runner/work/coder/coder/coderd/telemetry/telemetry.go:355
- Post "http://127.0.0.1:56934/deployment": net/http: HTTP/1.x transport connection broken: http: CloseIdleConnections called
```
I think the flake manifests when a test running in parallel in the same package calls `CloseIdleConnections` on the default client.
To avoid the flakes, we should refactor our code to stop using the global HTTP client and use local instances instead.
Related issues:
- https://github.com/coder/internal/issues/645
- https://github.com/coder/internal/issues/920
- https://github.com/coder/internal/issues/1016
- https://github.com/coder/internal/issues/835
- https://github.com/coder/internal/issues/582
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.