From c5386b88ad9fe4082670dd64976e0cfe8f11152f Mon Sep 17 00:00:00 2001 From: Cubarco Date: Fri, 11 Nov 2022 14:42:57 +0800 Subject: [PATCH] Fix sockopt.TcpKeepAliveInterval The Keep-Alive configs may be overridden with golang default settings when `tcpKeepAliveInterval` is set without `tcpKeepAliveIdle`. Adopt: https://github.com/XTLS/Xray-core/pull/1328 --- transport/internet/system_dialer.go | 2 +- transport/internet/system_listener.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/transport/internet/system_dialer.go b/transport/internet/system_dialer.go index 626792574df..314664a784a 100644 --- a/transport/internet/system_dialer.go +++ b/transport/internet/system_dialer.go @@ -64,7 +64,7 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne }, nil } goStdKeepAlive := time.Duration(0) - if sockopt != nil && sockopt.TcpKeepAliveIdle != 0 { + if sockopt != nil && (sockopt.TcpKeepAliveInterval != 0 || sockopt.TcpKeepAliveIdle != 0) { goStdKeepAlive = time.Duration(-1) } dialer := &net.Dialer{ diff --git a/transport/internet/system_listener.go b/transport/internet/system_listener.go index d95f2d542a4..5ddb4814e6f 100644 --- a/transport/internet/system_listener.go +++ b/transport/internet/system_listener.go @@ -50,7 +50,7 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S network = addr.Network() address = addr.String() lc.Control = getControlFunc(ctx, sockopt, dl.controllers) - if sockopt != nil && sockopt.TcpKeepAliveIdle != 0 { + if sockopt != nil && (sockopt.TcpKeepAliveInterval != 0 || sockopt.TcpKeepAliveIdle != 0) { lc.KeepAlive = time.Duration(-1) } case *net.UnixAddr: