Solution
There are two scenarios when an RST flag can be sent out. In one scenario it is an expected behavior and in the other scenario, it is a bug which got fixed in LabVIEW 2022.
The Expected Scenario:The RST flag is sent normally in situations where one side (e.g. client) has already requested to terminate the connection via a FIN flag, but still the other side (e.g. server) tries to send some data.
In the following discussion, let's assume the client side wants to terminate a connection and calls the "TCP Close Connection" VI.
Now, if the timings are not taken care of properly on the server side, there can be situations where although the client side has sent the FIN flag, the server side does not notice it fast enough and still sends some data to the client side. When the client receives a packet with some data, after already having sent the FIN flag, it sends out the RST flag to terminate the connection immediately.
This is an expected scenario. As an example, here I ran the LabVIEW example "Simple TCP" project, and along with some successful terminations with FIN flags (not visible in the following screenshot though), I also saw the following instance where an RST flag was sent. But, we can see that the clientside had already sent a FIN flag, but the server side still tried to send some data (with a PSH flag) before actually noticing/detecting the FIN sent by the client already. So here, when the clientside sees some incoming data despite already having sent the FIN flag, it terminates the connection forcefully by sending RST.
The Unexpected Scenario:If your scenario is not as we discussed above and you are using LabVIEW 2021 or earlier, you can still see some occurrences where an RST flag will be sent instead of a FIN flag when the "TCP Close Connection" VI is being executed. This is a bug in the TCP endpoint implementation in LabVIEW 2021 and older.
To fix this, you can update to LabVIEW 2022 or newer.
If updating to a newer version is not feasible for you due to some reasons, kindly download and use the VI attached at the end of this page. This is a workaround VI which will fix the issue. You will need to use this VI in place of the "TCP Close Connection.vi". Please follow the steps below.
- Download the attached "Close TCP Input.vi".
- Store it in the same folder as your client-side LabVIEW project/app.
- Load this VI in your LabVIEW project.
- Now delete the "TCP Close Connection" VIs from your VI.
- Drag the "Close TCP Input.vi" from the LabVIEW Project Explorer and drop it in your VI.
- Wire this VI in place of the "TCP Close Connection" VIs.
Note: This is a password-protected VI. You do not need to modify anything inside this VI. You can simply use it to replace the TCP Close Connection VI, as described.
After replacing the VI, each time you close the connection (by using this workaround VI) a FIN flag will be sent and not an RST flag. Hence the issue will be fixed.