From accbfde61e95e19cdddf2593707875b476679a8d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 30 May 2025 12:18:44 +0200 Subject: [PATCH] client: use go-winio.DialPipe directly The go-connections package implementation is only a shallow wrapper around go-winio for named pipes; use the go-winio implementation directly. Signed-off-by: Sebastiaan van Stijn --- client/client.go | 4 +++- client/client_unix.go | 11 +++++++++++ client/client_windows.go | 12 ++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index d6e014dddf..8acfb7f490 100644 --- a/client/client.go +++ b/client/client.go @@ -463,7 +463,9 @@ 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) + ctx, cancel := context.WithTimeout(ctx, 32*time.Second) + defer cancel() + return dialPipeContext(ctx, cli.addr) default: if tlsConfig := cli.tlsConfig(); tlsConfig != nil { return tls.Dial(cli.proto, cli.addr, tlsConfig) diff --git a/client/client_unix.go b/client/client_unix.go index e5b921b406..1fb9fbfb9e 100644 --- a/client/client_unix.go +++ b/client/client_unix.go @@ -2,6 +2,17 @@ package client +import ( + "context" + "net" + "syscall" +) + // DefaultDockerHost defines OS-specific default host if the DOCKER_HOST // (EnvOverrideHost) environment variable is unset or empty. const DefaultDockerHost = "unix:///var/run/docker.sock" + +// dialPipeContext connects to a Windows named pipe. It is not supported on non-Windows. +func dialPipeContext(_ context.Context, _ string) (net.Conn, error) { + return nil, syscall.EAFNOSUPPORT +} diff --git a/client/client_windows.go b/client/client_windows.go index 19b954b2fd..b471c06124 100644 --- a/client/client_windows.go +++ b/client/client_windows.go @@ -1,5 +1,17 @@ package client +import ( + "context" + "net" + + "github.com/Microsoft/go-winio" +) + // DefaultDockerHost defines OS-specific default host if the DOCKER_HOST // (EnvOverrideHost) environment variable is unset or empty. const DefaultDockerHost = "npipe:////./pipe/docker_engine" + +// dialPipeContext connects to a Windows named pipe. It is not supported on non-Windows. +func dialPipeContext(ctx context.Context, addr string) (net.Conn, error) { + return winio.DialPipeContext(ctx, addr) +}