Skip to content

Commit

Permalink
Fix sockopt.TcpKeepAliveInterval
Browse files Browse the repository at this point in the history
The Keep-Alive configs may be overridden with golang default settings when `tcpKeepAliveInterval` is set without `tcpKeepAliveIdle`.
Adopt: XTLS/Xray-core#1328
  • Loading branch information
cubarco committed Nov 11, 2022
1 parent 9bbc3af commit 10d3113
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion transport/internet/system_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion transport/internet/system_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 10d3113

Please sign in to comment.