4

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

1
  • 1
    The default TCP keepalive parameters can be overriden and moreover an application can set the TCP keepalive parameters on a per socket basis; it is not the implementation of TCP that necessarily determines them. The TCP connection in the capture was terminated normally. Something at the application layer terminated the connection. I don't think there is anything suggesting a TCP bug in the capture. You might want to try netcat-keepalive (github.com/cyberelf/netcat-keepalive) to see what happens when you specifiy your own keepalive parameters. Commented Jan 4, 2021 at 0:55

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

Comments

0

So I figured this out. Unfortunately, the WSL2 implementation of Debian seems to have this hardcoded in the stack. I tried to change the parameters of the socket open call and they didn't cause a change in the behavior.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.