Skip to content

Commit

Permalink
Merge pull request #5779 from jsternberg/remove-go-connections
Browse files Browse the repository at this point in the history
testutil: remove go-connections/sockets dependency
  • Loading branch information
tonistiigi authored Feb 26, 2025
2 parents 15482b6 + 718b1f0 commit f2752a8
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 283 deletions.
8 changes: 2 additions & 6 deletions util/testutil/dockerd/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"strings"
"time"

"github.com/docker/go-connections/sockets"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -164,14 +163,11 @@ func defaultHTTPClient(hostURL *url.URL) (*http.Client, error) {
// Necessary to prevent long-lived processes using the
// client from leaking connections due to idle connections
// not being released.
// TODO: see if we can also address this from the server side,
// or in go-connections.
// see: https://github.com/moby/moby/issues/45539
transport := &http.Transport{
MaxIdleConns: 6,
IdleConnTimeout: 30 * time.Second,
}
if err := sockets.ConfigureTransport(transport, hostURL.Scheme, hostURL.Host); err != nil {
if err := configureTransport(transport, hostURL.Scheme, hostURL.Host); err != nil {
return nil, err
}
return &http.Client{
Expand Down Expand Up @@ -241,7 +237,7 @@ func (cli *Client) Dialer() func(context.Context) (net.Conn, error) {
case "unix":
return net.Dial(cli.proto, cli.addr)
case "npipe":
return sockets.DialPipe(cli.addr, 32*time.Second)
return DialPipe(cli.addr, 32*time.Second)
default:
if tlsConfig := cli.tlsConfig(); tlsConfig != nil {
return tls.Dial(cli.proto, cli.addr, tlsConfig)
Expand Down
3 changes: 1 addition & 2 deletions util/testutil/dockerd/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package client
import (
"net/http"

"github.com/docker/go-connections/sockets"
"github.com/pkg/errors"
)

Expand All @@ -22,7 +21,7 @@ func WithHost(host string) Opt {
c.addr = hostURL.Host
c.basePath = hostURL.Path
if transport, ok := c.client.Transport.(*http.Transport); ok {
return sockets.ConfigureTransport(transport, c.proto, c.addr)
return configureTransport(transport, c.proto, c.addr)
}
return errors.Errorf("cannot apply host to transport: %T", c.client.Transport)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
// Package sockets provides helper functions to create and configure Unix or TCP sockets.
package sockets
package client

import (
"errors"
"net"
"net/http"
"time"
)

const defaultTimeout = 10 * time.Second

// ErrProtocolNotAvailable is returned when a given transport protocol is not provided by the operating system.
var ErrProtocolNotAvailable = errors.New("protocol not available")

// ConfigureTransport configures the specified [http.Transport] according to the specified proto
// configureTransport configures the specified [http.Transport] according to the specified proto
// and addr.
//
// If the proto is unix (using a unix socket to communicate) or npipe the compression is disabled.
// For other protos, compression is enabled. If you want to manually enable/disable compression,
// make sure you do it _after_ any subsequent calls to ConfigureTransport is made against the same
// [http.Transport].
func ConfigureTransport(tr *http.Transport, proto, addr string) error {
func configureTransport(tr *http.Transport, proto, addr string) error {
switch proto {
case "unix":
return configureUnixTransport(tr, proto, addr)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
//go:build !windows

package sockets
package client

import (
"context"
"fmt"
"net"
"net/http"
"syscall"
"time"

"github.com/pkg/errors"
)

const maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path)

func configureUnixTransport(tr *http.Transport, proto, addr string) error {
if len(addr) > maxUnixSocketPathSize {
return fmt.Errorf("unix socket path %q is too long", addr)
return errors.Errorf("unix socket path %q is too long", addr)
}
// No need for compression in local communications.
tr.DisableCompression = true
Expand All @@ -28,8 +29,8 @@ func configureUnixTransport(tr *http.Transport, proto, addr string) error {
return nil
}

func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
return ErrProtocolNotAvailable
func configureNpipeTransport(_ *http.Transport, _, _ string) error {
return errors.New("protocol not available")
}

// DialPipe connects to a Windows named pipe.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sockets
package client

import (
"context"
Expand All @@ -7,13 +7,14 @@ import (
"time"

"github.com/Microsoft/go-winio"
"github.com/pkg/errors"
)

func configureUnixTransport(tr *http.Transport, proto, addr string) error {
return ErrProtocolNotAvailable
func configureUnixTransport(_ *http.Transport, _, _ string) error {
return errors.New("protocol not available")
}

func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
func configureNpipeTransport(tr *http.Transport, _, addr string) error {
// No need for compression in local communications.
tr.DisableCompression = true
tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
Expand Down
Empty file.
81 changes: 0 additions & 81 deletions vendor/github.com/docker/go-connections/sockets/inmem_socket.go

This file was deleted.

28 changes: 0 additions & 28 deletions vendor/github.com/docker/go-connections/sockets/proxy.go

This file was deleted.

22 changes: 0 additions & 22 deletions vendor/github.com/docker/go-connections/sockets/tcp_socket.go

This file was deleted.

Loading

0 comments on commit f2752a8

Please sign in to comment.