C#-TCP-Clients keeps waiting on Receive-Method forever

Overview

We have a TCP-communication between a PC and a Toradex Evalboard with IMX6. Network outage longer than 10s cause the client to get stuck and waiting forever for the data from the server. We expect that the client throws a SocketException if he can no longer communicate with the server. We don’t want the client to get stuck on the NetworkStream.Receive(…)-method. This issue only occurs with Colibri IMX6, it does not occur with Colibri PXA.

Detailed Description

On the Toradex Evaluation Board there is a TCP-server listening on port 64001. On the PC there is a TCP-client which connects to this port 64001.

Step-by-step description if the network cable is NOT unplugged
Client: sends a “POST /” to the server and is waiting to receive text from server
Server sends:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 25

Server is waiting 10 seconds and then sends:
this is data !!! and even more data
Client receives data and writes it to the console.

Step-by-step description if the network cable is UNPLUGGED
But if the network cable is unplugged for more than 10 s and then plugged in again the client is waiting forever to receive data from the server. Here a step-by-step description of this:

Client: sends a “POST /” to the server and waiting to receive text from server
Server sends:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 25

User unplugs network cable from PC
Server is waiting 10 seconds and then sends:
this is data !!! and even more data
User plugs in network cable again into the PC
Client writes this to the console and then waits forever:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 25

Description of the environment

TCP-server is running on:
Toradex Colibri Evaluation Board 3.2
Colibri IMX 6 DL512MB IT
WinCE8.0 BSP 1.6
Compact Framework 3.9

Error occurs with original Toradex WinCompact2013 image “103192-imx6-wince-image.zip”, version 1.7
This issue does not occur with Colibri PXA 310 and WinCE6.0.

TCP Server
TCP-Server is implemented in C# and Compact Framework 3.8. The file “ConsoleApplication1.zip” contains the Visual Studio Solution 2015 for the server.

TCP Client
TCP-Client is running on a PC with Windows 10 Enterprise Version 20H2 with .NET Framework 4.8. The file “ClientTestApplication.zip” is the Visual Studio Solution 2019-solution for the client.

WireShark

To investigate this issue we used a network switch with port 1 mirrored to port 5.
Port 1: Toradex Eval Board/Colibri IMX with IP10.41.46.10/24
Port 2: C#-client running on PC with IP 10.41.46.11/24
Port 5: PC with Wireshark with IP 10.41.46.219/24

In Wireshark we can see 4 TCP retransmissions. Last retransmission is 6 seconds after sending the TCP-packet for the first time (Packet-IDs 1600, 1603, 1608 and 1619). We can also see ARP-requests “Who has 10.41.46.11” (Packet-IDs 1625, 1630 etc.) and an ARP-reply “ARP announcement for 10.41.46.11” (Packet-ID 1732) after the cable is plugged in again. But the is no TCP-retransmission anymore.

The wireshark-file can be downloaded here:
TCP_Communication_10-41-46-11_10-41-46-10-network-interruption__TcpMaxDataRetransmission_not_set_client_is_blocking2.pcapng

Please use this filter in WireShark:
(ip.addr != 10.41.46.219 && (tcp)) || (arp.src.proto_ipv4 == 10.41.46.10) || (arp.src.hw_mac == c8:5b:76:bc:21:c2)

Found Solution

After investigating for some time we found a Windows-registry key named
TcpMaxDataRetransmissions” under “HKEY_LOCAL_MACHINE\Comm\Tcpip\Parms”, which allows to adjust the number of TCP-retransmissions in case of network outage.
Here is the documentation: IPv4 and IPv6 Configurable Registry Settings (Compact 2013) | Microsoft Learn

In Wireshark we can see again the 4 TCP-retransmits (Packet-IDs 119, 120, 129 and 172)
followed by ARP-requests “Who has 10.41.46.11” (Packet-IDs 195, 216, 219 etc) and an ARP-reply “ARP announcement for 10.41.46.11” (Packet-ID 459) after the cable is plugged in. This time however there is a 5th TCP-retransmission (Packet-ID 712). The client can now read the text from the server is no longer stuck in NetworkStream.Read(…)-method.

The wireshark-file can be downloaded here:
TCP_Communication_10-41-46-11_10-41-46-10-network-interruption__TcpMaxDataRetransmission=220.pcapng

1 Like

Hi @ezeh ,

Welcome to the Toradex community.

Thanks for leaving this here other users will surely appreciate it.

If Toradex can help you anywhere let us know.

Best Regards
Kevin

I am the original poster of the question and I was investigating this issue further and found the suggested solution above is not complete.

Setting the WinRegistry-Key " TcpMaxDataRetransmissions" only work if all IP-adresses ared fixed and DHCP is turned off.

But…

Using DHCP-server causes “Toradex Colibri Evaluation”-board to request a new IP-address whener the Ethernet-Cable (RJ-45) is plugged out and plugged in. The requesting of new IP-address seems to make the network card unavailable for some time and causes the TCP-client to get stuck again on method NetworkStream. Receive(…)

Solution: setting “DisableDHCPMediaSense”=1 in “ HKEY_LOCAL_MACHINE\Comm\Tcpip\Parms ”. This way no IP-addresses are requested whenever the Ethernet-Cable (RJ-45) is plugged out and plugged.