Skip to content

Commit f5b5d81

Browse files
Set keepaliveidle time more aggressive against connection drops (danielpaulus#540)
Keepaliveidle time should be set more aggresive than the gVisor's 2 hours default idle time. Many NAT and firewalls drop the idle connections more aggressively (30-60 secs apparently). Keepaliveinterval option doesn't take affect as the keep alive probe doesn't start before the idle time reaches. It is 2 hours by default and before it reaches NAT/Firewall close the connection unlike kernel mode TUN device, With this change the idle time will be more aggressive and according to several tests this fix connection drops. Long running test more than 24 hours achieved with this fix.
1 parent 0f1771b commit f5b5d81

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ios/tunnel/userspace_tunnel.go

+6
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ func (iface *UserSpaceTUNInterface) TunnelRWCThroughInterface(localPort uint16,
6363
if err != nil {
6464
return fmt.Errorf("TunnelRWCThroughInterface: NewEndpoint failed: %+v", err)
6565
}
66+
6667
ep.SocketOptions().SetKeepAlive(true)
68+
// Set keep alive idle value more aggresive than the gVisor's 2 hours. NAT and Firewalls can drop the idle connections more aggresive.
69+
p := tcpip.KeepaliveIdleOption(30 * time.Second)
70+
ep.SetSockOpt(&p)
71+
6772
o := tcpip.KeepaliveIntervalOption(1 * time.Second)
6873
ep.SetSockOpt(&o)
74+
6975
// Bind if a port is specified.
7076
if localPort != 0 {
7177
if err := ep.Bind(tcpip.FullAddress{Port: localPort}); err != nil {

0 commit comments

Comments
 (0)