Tune tcp keep-alives with new kernel timeout options (#9963)

For more deeper understanding https://blog.cloudflare.com/when-tcp-sockets-refuse-to-die/
This commit is contained in:
Harshavardhana
2020-07-03 10:03:41 -07:00
committed by GitHub
parent 21a37e3393
commit e59ee14f40
8 changed files with 63 additions and 55 deletions

View File

@@ -21,18 +21,23 @@ package http
import (
"context"
"net"
"syscall"
"time"
)
// TODO: if possible implement for non-linux platforms, not a priority at the moment
func setTCPParameters(c syscall.RawConn) error {
return nil
}
// DialContext is a function to make custom Dial for internode communications
type DialContext func(ctx context.Context, network, address string) (net.Conn, error)
// NewCustomDialContext configures a custom dialer for internode communications
func NewCustomDialContext(dialTimeout, dialKeepAlive time.Duration) DialContext {
func NewCustomDialContext(dialTimeout time.Duration) DialContext {
return func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := &net.Dialer{
Timeout: dialTimeout,
KeepAlive: dialKeepAlive,
Timeout: dialTimeout,
}
return dialer.DialContext(ctx, network, addr)
}