Skip to content

stop using the default, global HTTP client to avoid CloseIdleConnections flakes #1020

@hugodutka

Description

@hugodutka

Some places in coder/coder, like this, use the default, global HTTP client:

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions