Skip to content

Commit

Permalink
socket: restore deprecated Transport.Dial (for now)
Browse files Browse the repository at this point in the history
This restores the deprecated Transport.Dial, which were removed in commits:

- 61039d0 (Replace deprecated Transport.Dial with Transport.DialContext)
- fb772cf (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 moby/moby#41042 and moby/moby#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 <github@gone.nl>
  • Loading branch information
thaJeztah committed Jul 26, 2021
1 parent af95011 commit b353ece
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
1 change: 1 addition & 0 deletions go.mod
Expand Up @@ -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
)
11 changes: 8 additions & 3 deletions 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=
33 changes: 30 additions & 3 deletions sockets/proxy.go
Expand Up @@ -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
Expand All @@ -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
}
8 changes: 8 additions & 0 deletions sockets/sockets.go
Expand Up @@ -3,6 +3,7 @@ package sockets

import (
"errors"
"net"
"net/http"
"time"
)
Expand All @@ -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
}
3 changes: 3 additions & 0 deletions sockets/sockets_unix.go
Expand Up @@ -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,
}
Expand Down
3 changes: 3 additions & 0 deletions sockets/sockets_windows.go
Expand Up @@ -24,6 +24,9 @@ func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
//return winio.DialPipeContext(ctx, addr)
return DialPipe(addr, defaultTimeout)
}
tr.Dial = func(_, _ string) (net.Conn, error) { //nolint: staticcheck // SA1019: tr.Dial is deprecated: Use DialContext instead
return DialPipe(addr, defaultTimeout)
}
return nil
}

Expand Down

0 comments on commit b353ece

Please sign in to comment.