From 61039d0834e53e8ae181e064229a9e79d7cd77aa Mon Sep 17 00:00:00 2001 From: Paul Donohue Date: Tue, 16 Apr 2019 11:56:36 -0400 Subject: [PATCH] Replace deprecated Transport.Dial with Transport.DialContext Signed-off-by: Paul Donohue --- sockets/sockets.go | 2 +- sockets/sockets_unix.go | 7 +++++-- sockets/sockets_windows.go | 10 +++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sockets/sockets.go b/sockets/sockets.go index a1d7beb4d..0540735c3 100644 --- a/sockets/sockets.go +++ b/sockets/sockets.go @@ -32,7 +32,7 @@ func ConfigureTransport(tr *http.Transport, proto, addr string) error { if err != nil { return err } - tr.Dial = dialer.Dial + tr.DialContext = dialer.DialContext } return nil } diff --git a/sockets/sockets_unix.go b/sockets/sockets_unix.go index 386cf0dbb..fd69d45aa 100644 --- a/sockets/sockets_unix.go +++ b/sockets/sockets_unix.go @@ -18,8 +18,11 @@ 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) { - return net.DialTimeout(proto, addr, defaultTimeout) + dialer := &net.Dialer{ + Timeout: defaultTimeout, + } + tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) { + return dialer.DialContext(ctx, proto, addr) } return nil } diff --git a/sockets/sockets_windows.go b/sockets/sockets_windows.go index 5c21644e1..f6462eda5 100644 --- a/sockets/sockets_windows.go +++ b/sockets/sockets_windows.go @@ -15,7 +15,15 @@ func configureUnixTransport(tr *http.Transport, proto, addr string) error { func configureNpipeTransport(tr *http.Transport, proto, addr string) error { // No need for compression in local communications. tr.DisableCompression = true - tr.Dial = func(_, _ string) (net.Conn, error) { + dialer := &net.Dialer{ + Timeout: defaultTimeout, + } + tr.DialContext = func(ctx context.Context, _, _ string) (net.Conn, error) { + // 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