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

testutil: remove go-connections/sockets dependency #5779

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
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
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
Loading