From 19fbef258de58727318b1b465731a7addc243d27 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 22 Jul 2021 14:00:26 +0200 Subject: [PATCH 1/3] Revert "sockets: defaultTimeout is unused on Windows (deadcode)" This reverts commit fcf9eb72347e4bfa9f9c64b557aaa0ac032c8f9c. Signed-off-by: Sebastiaan van Stijn --- 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 e74611c3188d524fd37967c85a2eb749908529e1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 22 Jul 2021 10:46:31 +0200 Subject: [PATCH 2/3] socket: restore deprecated Transport.Dial (for now) This restores the deprecated Transport.Dial, which were removed in commits: - 61039d0834e53e8ae181e064229a9e79d7cd77aa (Replace deprecated Transport.Dial with Transport.DialContext) - fb772cf57ab026bb75d4b3808e9b1761cd66e6c4 (Fix problems introduced by 61039d0) While we should still look at removing these, the moby code currently looks to be depending on their behavior. Removing them caused CI to fail, which blocked us from updating to the current version of this package. With those changes, Windows clients in CI were connecting with the wrong daemon, causing CI failures: Failed failed to get info from daemon: Error response from daemon: client version 1.41 is too new. Maximum supported API version is 1.40 exit status 1 FAIL github.com/docker/docker/integration/build 0.219s More details on https://github.com/moby/moby/pull/41042 and https://github.com/moby/moby/pull/41084 This patch restores the deprecated parts, but keeps the new variants as well, so that we can perform the migration in Moby when possible (after which they can be removed again) Signed-off-by: Sebastiaan van Stijn --- go.mod | 1 + go.sum | 11 ++++++++--- sockets/proxy.go | 33 ++++++++++++++++++++++++++++++--- sockets/sockets.go | 8 ++++++++ sockets/sockets_unix.go | 3 +++ sockets/sockets_windows.go | 3 +++ 6 files changed, 53 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 70ec3128f..bb3d4d890 100644 --- a/go.mod +++ b/go.mod @@ -5,4 +5,5 @@ go 1.13 require ( github.com/Microsoft/go-winio v0.4.14 github.com/pkg/errors v0.9.1 + golang.org/x/net v0.0.0-20210716203947-853a461950ff ) diff --git a/go.sum b/go.sum index 2bcfb4ffb..a2d8dc6be 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,21 @@ github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +golang.org/x/net v0.0.0-20210716203947-853a461950ff h1:j2EK/QoxYNBsXI4R7fQkkRUk8y6wnOBI+6hgPdP/6Ds= +golang.org/x/net v0.0.0-20210716203947-853a461950ff/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/sockets/proxy.go b/sockets/proxy.go index c897cb02a..2954bb96e 100644 --- a/sockets/proxy.go +++ b/sockets/proxy.go @@ -2,8 +2,11 @@ package sockets import ( "net" + "net/url" "os" "strings" + + "golang.org/x/net/proxy" ) // GetProxyEnv allows access to the uppercase and the lowercase forms of @@ -17,12 +20,36 @@ func GetProxyEnv(key string) string { return proxyValue } -// DialerFromEnvironment was previously used to configure a net.Dialer to route +// DialerFromEnvironment is used to configure a net.Dialer to route // connections through a SOCKS proxy. +// // DEPRECATED: SOCKS proxies are now supported by configuring only // http.Transport.Proxy, and no longer require changing http.Transport.Dial. // Therefore, only sockets.ConfigureTransport() needs to be called, and any // sockets.DialerFromEnvironment() calls can be dropped. -func DialerFromEnvironment(direct *net.Dialer) (*net.Dialer, error) { - return direct, nil +func DialerFromEnvironment(direct *net.Dialer) (proxy.Dialer, error) { + allProxy := GetProxyEnv("all_proxy") + if len(allProxy) == 0 { + return direct, nil + } + + proxyURL, err := url.Parse(allProxy) + if err != nil { + return direct, err + } + + proxyFromURL, err := proxy.FromURL(proxyURL, direct) + if err != nil { + return direct, err + } + + noProxy := GetProxyEnv("no_proxy") + if len(noProxy) == 0 { + return proxyFromURL, nil + } + + perHost := proxy.NewPerHost(proxyFromURL, direct) + perHost.AddFromString(noProxy) + + return perHost, nil } diff --git a/sockets/sockets.go b/sockets/sockets.go index 73ff9fcb7..6e3cbe9b0 100644 --- a/sockets/sockets.go +++ b/sockets/sockets.go @@ -3,6 +3,7 @@ package sockets import ( "errors" + "net" "net/http" "time" ) @@ -24,6 +25,13 @@ func ConfigureTransport(tr *http.Transport, proto, addr string) error { return configureNpipeTransport(tr, proto, addr) default: tr.Proxy = http.ProxyFromEnvironment + dialer, err := DialerFromEnvironment(&net.Dialer{ + Timeout: defaultTimeout, + }) + if err != nil { + return err + } + tr.Dial = dialer.Dial //nolint: staticcheck // SA1019: tr.Dial is deprecated: Use DialContext instead } return nil } diff --git a/sockets/sockets_unix.go b/sockets/sockets_unix.go index 5b65c546a..1eed6d151 100644 --- a/sockets/sockets_unix.go +++ b/sockets/sockets_unix.go @@ -19,6 +19,9 @@ func configureUnixTransport(tr *http.Transport, proto, addr string) error { } // No need for compression in local communications. tr.DisableCompression = true + tr.Dial = func(_, _ string) (net.Conn, error) { //nolint: staticcheck // SA1019: tr.Dial is deprecated: Use DialContext instead + return net.DialTimeout(proto, addr, defaultTimeout) + } dialer := &net.Dialer{ Timeout: defaultTimeout, } diff --git a/sockets/sockets_windows.go b/sockets/sockets_windows.go index 7acafc5a2..4050008b8 100644 --- a/sockets/sockets_windows.go +++ b/sockets/sockets_windows.go @@ -19,6 +19,9 @@ func configureNpipeTransport(tr *http.Transport, proto, addr string) error { tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) { return winio.DialPipeContext(ctx, addr) } + tr.Dial = func(_, _ string) (net.Conn, error) { //nolint: staticcheck // SA1019: tr.Dial is deprecated: Use DialContext instead + return DialPipe(addr, defaultTimeout) + } return nil } From 724051587792b563352b0ae5c6dbde4cd1130ac1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 27 Jul 2021 22:45:54 +0200 Subject: [PATCH 3/3] TESTING: rolling back etc Signed-off-by: Sebastiaan van Stijn --- go.mod | 1 - go.sum | 9 +-------- sockets/proxy.go | 33 +++------------------------------ sockets/sockets.go | 8 -------- sockets/sockets_unix.go | 9 +++------ sockets/sockets_windows.go | 8 +++++--- 6 files changed, 12 insertions(+), 56 deletions(-) diff --git a/go.mod b/go.mod index bb3d4d890..70ec3128f 100644 --- a/go.mod +++ b/go.mod @@ -5,5 +5,4 @@ go 1.13 require ( github.com/Microsoft/go-winio v0.4.14 github.com/pkg/errors v0.9.1 - golang.org/x/net v0.0.0-20210716203947-853a461950ff ) diff --git a/go.sum b/go.sum index a2d8dc6be..6f7f4267b 100644 --- a/go.sum +++ b/go.sum @@ -9,13 +9,6 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -golang.org/x/net v0.0.0-20210716203947-853a461950ff h1:j2EK/QoxYNBsXI4R7fQkkRUk8y6wnOBI+6hgPdP/6Ds= -golang.org/x/net v0.0.0-20210716203947-853a461950ff/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA= golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/sockets/proxy.go b/sockets/proxy.go index 2954bb96e..c897cb02a 100644 --- a/sockets/proxy.go +++ b/sockets/proxy.go @@ -2,11 +2,8 @@ package sockets import ( "net" - "net/url" "os" "strings" - - "golang.org/x/net/proxy" ) // GetProxyEnv allows access to the uppercase and the lowercase forms of @@ -20,36 +17,12 @@ func GetProxyEnv(key string) string { return proxyValue } -// DialerFromEnvironment is used to configure a net.Dialer to route +// DialerFromEnvironment was previously used to configure a net.Dialer to route // connections through a SOCKS proxy. -// // DEPRECATED: SOCKS proxies are now supported by configuring only // http.Transport.Proxy, and no longer require changing http.Transport.Dial. // Therefore, only sockets.ConfigureTransport() needs to be called, and any // sockets.DialerFromEnvironment() calls can be dropped. -func DialerFromEnvironment(direct *net.Dialer) (proxy.Dialer, error) { - allProxy := GetProxyEnv("all_proxy") - if len(allProxy) == 0 { - return direct, nil - } - - proxyURL, err := url.Parse(allProxy) - if err != nil { - return direct, err - } - - proxyFromURL, err := proxy.FromURL(proxyURL, direct) - if err != nil { - return direct, err - } - - noProxy := GetProxyEnv("no_proxy") - if len(noProxy) == 0 { - return proxyFromURL, nil - } - - perHost := proxy.NewPerHost(proxyFromURL, direct) - perHost.AddFromString(noProxy) - - return perHost, nil +func DialerFromEnvironment(direct *net.Dialer) (*net.Dialer, error) { + return direct, nil } diff --git a/sockets/sockets.go b/sockets/sockets.go index 6e3cbe9b0..73ff9fcb7 100644 --- a/sockets/sockets.go +++ b/sockets/sockets.go @@ -3,7 +3,6 @@ package sockets import ( "errors" - "net" "net/http" "time" ) @@ -25,13 +24,6 @@ func ConfigureTransport(tr *http.Transport, proto, addr string) error { return configureNpipeTransport(tr, proto, addr) default: tr.Proxy = http.ProxyFromEnvironment - dialer, err := DialerFromEnvironment(&net.Dialer{ - Timeout: defaultTimeout, - }) - if err != nil { - return err - } - tr.Dial = dialer.Dial //nolint: staticcheck // SA1019: tr.Dial is deprecated: Use DialContext instead } return nil } diff --git a/sockets/sockets_unix.go b/sockets/sockets_unix.go index 1eed6d151..31b14abda 100644 --- a/sockets/sockets_unix.go +++ b/sockets/sockets_unix.go @@ -19,13 +19,10 @@ func configureUnixTransport(tr *http.Transport, proto, addr string) error { } // No need for compression in local communications. tr.DisableCompression = true - tr.Dial = func(_, _ string) (net.Conn, error) { //nolint: staticcheck // SA1019: tr.Dial is deprecated: Use DialContext instead - return net.DialTimeout(proto, addr, defaultTimeout) - } - dialer := &net.Dialer{ - Timeout: defaultTimeout, - } tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) { + dialer := &net.Dialer{ + Timeout: defaultTimeout, + } return dialer.DialContext(ctx, proto, addr) } return nil diff --git a/sockets/sockets_windows.go b/sockets/sockets_windows.go index 4050008b8..16f8cdbb1 100644 --- a/sockets/sockets_windows.go +++ b/sockets/sockets_windows.go @@ -17,9 +17,11 @@ func configureNpipeTransport(tr *http.Transport, proto, addr string) error { // No need for compression in local communications. tr.DisableCompression = true tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) { - return winio.DialPipeContext(ctx, addr) - } - tr.Dial = func(_, _ string) (net.Conn, error) { //nolint: staticcheck // SA1019: tr.Dial is deprecated: Use DialContext instead + // DialPipeContext() has been added to winio: + // https://github.com/Microsoft/go-winio/commit/5fdbdcc2ae1c7e1073157fa7cb34a15eab472e1d + // However, a new version of winio with this commit has not been released yet. + // Continue to use DialPipe() until DialPipeContext() becomes available. + //return winio.DialPipeContext(ctx, addr) return DialPipe(addr, defaultTimeout) } return nil