From 7c3d8cf8db1db985443fd35dd8ad48080be568b8 Mon Sep 17 00:00:00 2001 From: TargetLocked <32962687+TargetLocked@users.noreply.github.com> Date: Fri, 10 Apr 2026 13:29:15 +0800 Subject: [PATCH] Fix disable tcp keep alive --- common/dialer/default.go | 5 ++++- common/listener/listener_tcp.go | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/dialer/default.go b/common/dialer/default.go index 6b843ed04..4ffe00c1a 100644 --- a/common/dialer/default.go +++ b/common/dialer/default.go @@ -149,7 +149,10 @@ func NewDefault(ctx context.Context, options option.DialerOptions) (*DefaultDial } else { dialer.Timeout = C.TCPConnectTimeout } - if !options.DisableTCPKeepAlive { + if options.DisableTCPKeepAlive { + dialer.KeepAlive = -1 + dialer.KeepAliveConfig.Enable = false + } else { keepIdle := time.Duration(options.TCPKeepAlive) if keepIdle == 0 { keepIdle = C.TCPKeepAliveInitial diff --git a/common/listener/listener_tcp.go b/common/listener/listener_tcp.go index 899d444fe..54d84a6b7 100644 --- a/common/listener/listener_tcp.go +++ b/common/listener/listener_tcp.go @@ -37,7 +37,10 @@ func (l *Listener) ListenTCP() (net.Listener, error) { if l.listenOptions.ReuseAddr { listenConfig.Control = control.Append(listenConfig.Control, control.ReuseAddr()) } - if !l.listenOptions.DisableTCPKeepAlive { + if l.listenOptions.DisableTCPKeepAlive { + listenConfig.KeepAlive = -1 + listenConfig.KeepAliveConfig.Enable = false + } else { keepIdle := time.Duration(l.listenOptions.TCPKeepAlive) if keepIdle == 0 { keepIdle = C.TCPKeepAliveInitial