Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable keep alives to not keep dead connections #1036

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"regexp"
Expand All @@ -20,6 +21,7 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
"github.com/docker/go-connections/nat"
"github.com/docker/go-connections/sockets"
"github.com/orlangure/gnomock/internal/cleaner"
"github.com/orlangure/gnomock/internal/health"
"go.uber.org/zap"
Expand Down Expand Up @@ -50,10 +52,35 @@ type docker struct {
lock sync.Mutex
}

func dockerHTTPClient() (*http.Client, error) {
transport := &http.Transport{
DisableKeepAlives: true, // this is added to prevent go routine leakage
}

// docker client magic
err := sockets.ConfigureTransport(transport, "unix", dockerSockAddr)
if err != nil {
return nil, fmt.Errorf("can't configure default docker client: %w", err)
}

return &http.Client{
Transport: transport,
CheckRedirect: client.CheckRedirect,
}, nil
}

func (g *g) dockerConnect() (*docker, error) {
g.log.Info("connecting to docker engine")

cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
cl, err := dockerHTTPClient()
if err != nil {
return nil, err
}

cli, err := client.NewClientWithOpts(
client.WithHTTPClient(cl),
client.FromEnv,
client.WithAPIVersionNegotiation())
if err != nil {
return nil, errors.Join(ErrEnvClient, err)
}
Expand Down
Loading