title: TCP retransmission on RST - Different socket behaviour on Windows and Linux?
body: <p><strong>Summary:</strong> </p>
  
  <p>I am <em>guessing</em> that the issue here is something to do with how Windows and Linux handle TCP connections, or sockets, but I have no idea what it is. I'm initiating a TCP connection to a piece of custom hardware that someone else has developed and I am trying to understand its behaviour. In doing so, I've created a .Net core 2.2 application; run on a Windows system, I can initiate the connection successfully, but on Linux (latest Raspbian), I cannot. </p>
  
  <p>It appears that it may be because Linux systems do not try to retry/retransmit a SYN after a RST, whereas Windows ones do - and this behaviour seems key to how this peculiar piece of hardware works..</p>
  
  <p><strong>Background:</strong></p>
  
  <p>We have a black box piece of hardware that can be controlled and queried over a network, by using a manufacturer-supplied Windows application. Data is unencrypted and requires no authentication to connect to it and the application has some other issues. Ultimately, we want to be able to relay data from it to another system, so we decided to make our own application. </p>
  
  <p>I've spent quite a long time trying to understand the packet format and have created a library, which targets .net core 2.2, that can be used to successfully communicate with this kit. In doing so, I discovered that the device seems to require a kind of "request to connect" command to be sent, via UDP. Straight afterwards, I am able to initiate a TCP connection on port 16000, although the first TCP attempt always results in a RST,ACK being returned - so a second attempt needs to be made. </p>
  
  <p>What I've developed works absolutely fine on both Windows (x86) and Linux (Raspberry Pi/ARM) systems and I can send and receive data. However, when run on the Raspbian system, there seems to be problems when initiating the TCP connection. I could have sworn that we had it working absolutely fine on a previous build, but none of the previous commits seem to work - so it may well be a system/kernel update that has changed something.</p>
  
  <p><strong>The issue:</strong></p>
  
  <p>When initiating a TCP connection to this device, it will - straight away - reset the connection. It does this even with the manufacturer-supplied software, which itself then immediately re-attempts the connection again and it succeeds; so this kind of reset-once-then-it-works-the-second-time behaviour in itself isn't a "problem" that I have any control over.</p>
  
  <p>What I am trying to understand is why a Windows system immediately re-attempts the connection through a retransmission...
  <a href="https://i.stack.imgur.com/c5M5Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c5M5Z.png" alt="enter image description here"></a></p>
  
  <p>..but the Linux system just gives up after one attempt (this is the end of the packet capture..)
  <a href="https://i.stack.imgur.com/ED8ug.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ED8ug.png" alt="enter image description here"></a></p>
  
  <p>To prove it is not an application-specific issue, I've tried using ncat/netcat on both the Windows system and the Raspbian system, as well as a Kali system on a separate laptop to prove it isn't an ARM/Raspberry issue. Since the UDP "request" hasn't been sent, the connection will never succeed anyway, but this simply demonstrates different behaviour between the OSes. </p>
  
  <p>Linux versions look pretty much the same as above, whereby they send a single packet that gets reset - whereas the Windows attempt demonstrates the multiple retransmissions..</p>
  
  <p><a href="https://i.stack.imgur.com/L8T1X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L8T1X.png" alt="enter image description here"></a></p>
  
  <p>So, does anyone have any answer for this behaviour difference? I am guessing it isn't a .net core specific issue, but is there any way I can set socket options to attempt a retransmission? Or can it be set at the OS level with systemctl commands or something? I did try and see if there are any SocketOptionNames, in .net, that look like they'd control attempts/retries, as <a href="https://stackoverflow.com/questions/8427996/tcp-retransmissions-in-socket-configuration">this answer</a> had me wonder, but no luck so far.</p>
  
  <p>If anyone has any suggestions as to how to better align this behaviour across platforms, or can explain the reason for this difference is at all, I would very much appreciate it! </p>