Skip to content

Commit 548eb07

Browse files
committed
socket: restore deprecated Transport.Dial (for now)
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 <[email protected]>
1 parent 19fbef2 commit 548eb07

File tree

6 files changed

+53
-6
lines changed

6 files changed

+53
-6
lines changed

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ go 1.13
55
require (
66
github.com/Microsoft/go-winio v0.4.14
77
github.com/pkg/errors v0.9.1
8+
golang.org/x/net v0.0.0-20210716203947-853a461950ff
89
)

go.sum

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
github.com/Microsoft/go-winio v0.4.14 h1:+hMXMk01us9KgxGb7ftKQt2Xpf5hH/yky+TDA+qxleU=
22
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
3-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
43
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
54
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
65
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
76
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
87
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
9-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
108
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
119
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
1210
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1311
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
12+
golang.org/x/net v0.0.0-20210716203947-853a461950ff h1:j2EK/QoxYNBsXI4R7fQkkRUk8y6wnOBI+6hgPdP/6Ds=
13+
golang.org/x/net v0.0.0-20210716203947-853a461950ff/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
1414
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
15-
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b h1:ag/x1USPSsqHud38I9BAC88qdNLDHHtQ4mlgQIZPPNA=
1615
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
16+
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
17+
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
18+
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
19+
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
20+
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
21+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

sockets/proxy.go

+30-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package sockets
22

33
import (
44
"net"
5+
"net/url"
56
"os"
67
"strings"
8+
9+
"golang.org/x/net/proxy"
710
)
811

912
// GetProxyEnv allows access to the uppercase and the lowercase forms of
@@ -17,12 +20,36 @@ func GetProxyEnv(key string) string {
1720
return proxyValue
1821
}
1922

20-
// DialerFromEnvironment was previously used to configure a net.Dialer to route
23+
// DialerFromEnvironment is used to configure a net.Dialer to route
2124
// connections through a SOCKS proxy.
25+
//
2226
// DEPRECATED: SOCKS proxies are now supported by configuring only
2327
// http.Transport.Proxy, and no longer require changing http.Transport.Dial.
2428
// Therefore, only sockets.ConfigureTransport() needs to be called, and any
2529
// sockets.DialerFromEnvironment() calls can be dropped.
26-
func DialerFromEnvironment(direct *net.Dialer) (*net.Dialer, error) {
27-
return direct, nil
30+
func DialerFromEnvironment(direct *net.Dialer) (proxy.Dialer, error) {
31+
allProxy := GetProxyEnv("all_proxy")
32+
if len(allProxy) == 0 {
33+
return direct, nil
34+
}
35+
36+
proxyURL, err := url.Parse(allProxy)
37+
if err != nil {
38+
return direct, err
39+
}
40+
41+
proxyFromURL, err := proxy.FromURL(proxyURL, direct)
42+
if err != nil {
43+
return direct, err
44+
}
45+
46+
noProxy := GetProxyEnv("no_proxy")
47+
if len(noProxy) == 0 {
48+
return proxyFromURL, nil
49+
}
50+
51+
perHost := proxy.NewPerHost(proxyFromURL, direct)
52+
perHost.AddFromString(noProxy)
53+
54+
return perHost, nil
2855
}

sockets/sockets.go

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sockets
33

44
import (
55
"errors"
6+
"net"
67
"net/http"
78
"time"
89
)
@@ -24,6 +25,13 @@ func ConfigureTransport(tr *http.Transport, proto, addr string) error {
2425
return configureNpipeTransport(tr, proto, addr)
2526
default:
2627
tr.Proxy = http.ProxyFromEnvironment
28+
dialer, err := DialerFromEnvironment(&net.Dialer{
29+
Timeout: defaultTimeout,
30+
})
31+
if err != nil {
32+
return err
33+
}
34+
tr.Dial = dialer.Dial
2735
}
2836
return nil
2937
}

sockets/sockets_unix.go

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ func configureUnixTransport(tr *http.Transport, proto, addr string) error {
1919
}
2020
// No need for compression in local communications.
2121
tr.DisableCompression = true
22+
tr.Dial = func(_, _ string) (net.Conn, error) {
23+
return net.DialTimeout(proto, addr, defaultTimeout)
24+
}
2225
dialer := &net.Dialer{
2326
Timeout: defaultTimeout,
2427
}

sockets/sockets_windows.go

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ func configureNpipeTransport(tr *http.Transport, proto, addr string) error {
1919
tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) {
2020
return winio.DialPipeContext(ctx, addr)
2121
}
22+
tr.Dial = func(_, _ string) (net.Conn, error) {
23+
return DialPipe(addr, defaultTimeout)
24+
}
2225
return nil
2326
}
2427

0 commit comments

Comments
 (0)