Skip to content

Commit 12f72d4

Browse files
authored
Merge pull request #103 from akerouanton/fix-tcp-DialContext
ConfigureTransport: make sure a clean DialContext is used for tcp
2 parents 5cc4da5 + ffe640f commit 12f72d4

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

sockets/sockets.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ package sockets
33

44
import (
55
"errors"
6+
"net"
67
"net/http"
8+
"time"
79
)
810

11+
const defaultTimeout = 10 * time.Second
12+
913
// ErrProtocolNotAvailable is returned when a given transport protocol is not provided by the operating system.
1014
var ErrProtocolNotAvailable = errors.New("protocol not available")
1115

@@ -21,6 +25,9 @@ func ConfigureTransport(tr *http.Transport, proto, addr string) error {
2125
return configureNpipeTransport(tr, proto, addr)
2226
default:
2327
tr.Proxy = http.ProxyFromEnvironment
28+
tr.DialContext = (&net.Dialer{
29+
Timeout: defaultTimeout,
30+
}).DialContext
2431
}
2532
return nil
2633
}

sockets/sockets_unix.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import (
1111
"time"
1212
)
1313

14-
const (
15-
defaultTimeout = 10 * time.Second
16-
maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path)
17-
)
14+
const maxUnixSocketPathSize = len(syscall.RawSockaddrUnix{}.Path)
1815

1916
func configureUnixTransport(tr *http.Transport, proto, addr string) error {
2017
if len(addr) > maxUnixSocketPathSize {

0 commit comments

Comments
 (0)