Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSL2 + Docker - Keep Alive Bug in TCP stack

I wonder if others noticed this issue with the WSL2 Debian implementation of TCP.

I am connecting from a Docker container running WSL2 Debian v. 20

The TCP client sends a Keep-Alive packet every second which is kind of overkill. Then after roughly 5 minutes, the client terminates the connection without any reason. Is anybody seeing this behavior?

You can reproduce this by just opening a telnet session to another host. But the behavior happens on other types of sockets too.

And before you ask, this issue is not caused by the server, it does not occur when opening the same tcp connection from other hosts.

wireshark dump of the last few seconds of the idle TCP connection

like image 423
giac Avatar asked Oct 15 '25 01:10

giac


1 Answers

I had the same problem with Ubuntu on WSL2. An outbound ssh connection closed after a period of time if there was no activity on that connection. Particularly anoying if you were running an application that produced no screen output.

I suspect that the internal router that connects wsl to the local network dropped the idle TCP connection.

The solution was to shorten the TCP keep-alive timers in /proc/sys/net/ipv4, the following worked for me:

echo 300 > /proc/sys/net/tcp_keepalive_time
echo 45  > /proc/sys/net/tcp_keepalive_intvl
like image 193
voipcode Avatar answered Oct 17 '25 16:10

voipcode