From a83cc44bf3aceb792fce2feefdb11d071590a2d2 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Mon, 30 Oct 2023 09:37:33 +0100 Subject: [PATCH 1/2] Revert "sockets: defaultTimeout is unused on Windows (deadcode)" This reverts commit fcf9eb72347e4bfa9f9c64b557aaa0ac032c8f9c. Signed-off-by: Albin Kerouanton --- sockets/sockets.go | 3 +++ sockets/sockets_unix.go | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sockets/sockets.go b/sockets/sockets.go index 2e9e9006f..73ff9fcb7 100644 --- a/sockets/sockets.go +++ b/sockets/sockets.go @@ -4,8 +4,11 @@ package sockets import ( "errors" "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") diff --git a/sockets/sockets_unix.go b/sockets/sockets_unix.go index 10d763426..5b65c546a 100644 --- a/sockets/sockets_unix.go +++ b/sockets/sockets_unix.go @@ -11,10 +11,7 @@ import ( "time" ) -const ( - defaultTimeout = 10 * time.Second - maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path) -) +const maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path) func configureUnixTransport(tr *http.Transport, proto, addr string) error { if len(addr) > maxUnixSocketPathSize { From ffe640f10bdbc8ad625d05070b244aa208ce7401 Mon Sep 17 00:00:00 2001 From: Albin Kerouanton Date: Fri, 27 Oct 2023 13:02:05 +0200 Subject: [PATCH 2/2] ConfigureTransport: make sure a clean DialContext is used for tcp Since #61, there's no more DialContext defined in the default switch case of ConfigureTransport. As a consequence, if ConfigureTransport was already called with a npipe or unix proto (ie. Docker client does that to initialize its HTTP client with the default DOCKER_HOST), the DialContext function defined by these protocols will be used. As the DialContext functions defined by unix and npipe protos totally ignore DialContext's 2nd and 3rd argument (ie. network and addr) and instead use the equivalent arguments passed to configureUnixTransport and configureNpipeTransport when they were called, this results in ConfigureTransport being totally ineffective. Signed-off-by: Albin Kerouanton --- sockets/sockets.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sockets/sockets.go b/sockets/sockets.go index 73ff9fcb7..0133ee1a5 100644 --- a/sockets/sockets.go +++ b/sockets/sockets.go @@ -3,6 +3,7 @@ package sockets import ( "errors" + "net" "net/http" "time" ) @@ -24,6 +25,9 @@ func ConfigureTransport(tr *http.Transport, proto, addr string) error { return configureNpipeTransport(tr, proto, addr) default: tr.Proxy = http.ProxyFromEnvironment + tr.DialContext = (&net.Dialer{ + Timeout: defaultTimeout, + }).DialContext } return nil }