mirror of https://github.com/docker/docs.git
Support TCP_USER_TIMEOUT for Linux and its equivalent in Mac
Signed-off-by: Dong Chen <dongluo.chen@docker.com>
This commit is contained in:
parent
af89c1e94a
commit
15c9dbaee0
|
@ -145,7 +145,7 @@ func (e *Engine) Connect(config *tls.Config) error {
|
||||||
}
|
}
|
||||||
e.IP = addr.IP.String()
|
e.IP = addr.IP.String()
|
||||||
|
|
||||||
c, err := dockerclient.NewDockerClientTimeout("tcp://"+e.Addr, config, time.Duration(requestTimeout), nil)
|
c, err := dockerclient.NewDockerClientTimeout("tcp://"+e.Addr, config, time.Duration(requestTimeout), setTCPUserTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
// +build darwin
|
||||||
|
|
||||||
|
package dockerclient
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// setTCPUserTimeout sets TCP_RXT_CONNDROPTIME on darwin
|
||||||
|
func setTCPUserTimeout(conn *net.TCPConn, uto time.Duration) error {
|
||||||
|
f, err := conn.File()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
secs := int(uto.Nanoseconds() / 1e9)
|
||||||
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(int(f.Fd()), syscall.IPPROTO_TCP, unix.TCP_RXT_CONNDROPTIME, secs))
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
// +build linux
|
||||||
|
|
||||||
|
package cluster
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// setTCPUserTimeout sets TCP_USER_TIMEOUT according to RFC5842
|
||||||
|
func setTCPUserTimeout(conn *net.TCPConn, uto time.Duration) error {
|
||||||
|
f, err := conn.File()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
msecs := int(uto.Nanoseconds() / 1e6)
|
||||||
|
// TCP_USER_TIMEOUT is a relatively new feature to detect dead peer from sender side.
|
||||||
|
// Linux supports it since kernel 2.6.37. It's among Golang experimental under
|
||||||
|
// golang.org/x/sys/unix but it doesn't support all Linux platforms yet.
|
||||||
|
// we explicitly define it here until it becomes official in golang.
|
||||||
|
// TODO: replace it with proper package when TCP_USER_TIMEOUT is supported in golang.
|
||||||
|
const tcpUserTimeout = 0x12
|
||||||
|
return os.NewSyscallError("setsockopt", syscall.SetsockoptInt(int(f.Fd()), syscall.IPPROTO_TCP, tcpUserTimeout, msecs))
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
// +build !linux,!darwin
|
||||||
|
|
||||||
|
package cluster
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"net"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// setTCPUserTimeout doesn't work under Windows because Go doesn't support
|
||||||
|
// the option and swarm doesn't support cgo
|
||||||
|
// This is a usability enhancement. Service shouldn't fail on this error.
|
||||||
|
func setTCPUserTimeout(conn *net.TCPConn, uto time.Duration) error {
|
||||||
|
return errors.New("Go doesn't have native support for TCP_USER_TIMEOUT for this platform")
|
||||||
|
}
|
Loading…
Reference in New Issue