add different TCP timeouts for internal and incoming (#10090)

closes #10086
This commit is contained in:
Harshavardhana 2020-07-19 17:16:12 -07:00 committed by GitHub
parent 7764c542f2
commit e2c71717f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 7 deletions

View File

@ -27,7 +27,7 @@ import (
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
func setTCPParameters(c syscall.RawConn) error { func setInternalTCPParameters(c syscall.RawConn) error {
return c.Control(func(fdPtr uintptr) { return c.Control(func(fdPtr uintptr) {
// got socket file descriptor to set parameters. // got socket file descriptor to set parameters.
fd := int(fdPtr) fd := int(fdPtr)
@ -67,7 +67,7 @@ func NewCustomDialContext(dialTimeout time.Duration) DialContext {
dialer := &net.Dialer{ dialer := &net.Dialer{
Timeout: dialTimeout, Timeout: dialTimeout,
Control: func(network, address string, c syscall.RawConn) error { Control: func(network, address string, c syscall.RawConn) error {
return setTCPParameters(c) return setInternalTCPParameters(c)
}, },
} }
return dialer.DialContext(ctx, network, addr) return dialer.DialContext(ctx, network, addr)

View File

@ -26,7 +26,7 @@ import (
) )
// TODO: if possible implement for non-linux platforms, not a priority at the moment // TODO: if possible implement for non-linux platforms, not a priority at the moment
func setTCPParameters(c syscall.RawConn) error { func setInternalTCPParameters(c syscall.RawConn) error {
return nil return nil
} }

View File

@ -81,10 +81,7 @@ func (listener *httpListener) start() {
// Closure to handle single connection. // Closure to handle single connection.
handleConn := func(tcpConn *net.TCPConn, doneCh <-chan struct{}) { handleConn := func(tcpConn *net.TCPConn, doneCh <-chan struct{}) {
rawConn, err := tcpConn.SyscallConn() tcpConn.SetKeepAlive(true)
if err == nil {
setTCPParameters(rawConn)
}
send(acceptResult{tcpConn, nil}, doneCh) send(acceptResult{tcpConn, nil}, doneCh)
} }