TCP FIN Received: Check the Open Direction Before Discarding the Reply
A client finishes sending a request and closes its sending direction. The server's reply may still be travelling in the other direction. An integration that treats the first FIN as “discard everything and reconnect” can lose the evidence needed to decide whether the application transaction completed.

TCP closes its directions independently. Transport shutdown and successful application processing require different evidence.
1. Establish which direction closed
Record the local and remote endpoints and identify which side sent FIN. In normal TCP operation, FIN indicates that its sender has no more data to send in that direction. It is distinct from a reset, which aborts the connection. RFC 9293 describes a half-closed connection as closed in only one direction, with data still permitted in the open direction.
For gateway and industrial networking projects, ask how the actual client, server and socket interface handle directional shutdown. Some interfaces and implementation choices close reception as well. Verify the behaviour rather than assuming a portable API name guarantees identical results everywhere.
Do not confuse this with a half-open connection caused by inconsistent endpoint state. Similar terminology can conceal different failure modes. A packet capture, socket-state record and application log should identify the actual sequence before a remedy is chosen.
2. Use the application contract to decide completeness
In a hypothetical test protocol, a client sends a complete request and then signals the end of its sending stream. The server returns a defined response after receiving that end marker. The client must follow that protocol's reply framing and completion rules; the first directional close cannot stand in for the response.
Other protocols use explicit lengths or message delimiters and do not use connection shutdown to mark a request. Apply their documented framing instead. Do not introduce half-close behaviour into an existing controller protocol merely because a generic demonstration uses it.
The Modbus TCP partial-reply guide addresses message assembly across stream reads. Keep that framing question separate from connection termination. A final stream read may contain useful bytes even when a later read reports end-of-stream; the application must assess those bytes against its expected message.

3. Retain the final response and its uncertainty
Record the complete request identifier where the protocol supplies one, received response bytes and the point at which end-of-stream or reset was reported. If a response is incomplete, preserve that condition explicitly. Do not fill missing fields with zeros or report success because a socket closed cleanly.
A clean transport close does not prove that a command was applied or durably stored. Use the application's documented acknowledgement and, where appropriate, an independent state check. An uncertain outcome needs a retry policy suited to the operation; blindly repeating a non-idempotent command can create another problem.
4. Build a directional acceptance test
Use a non-production fixture and capture the expected request and response.
Test ordinary completion under the documented protocol.
Test permitted directional shutdown while a reply remains pending.
Test incomplete reply and reset cases with separate expected outcomes.
Verify stored application state, error handling and operator messages.
Observed sequence | Required distinction |
FIN in one direction; reply continues | Half-close and remaining application data |
End-of-stream before a complete reply | Incomplete application response |
RST observed | Aborted connection evidence |
Complete response then normal close | Application acceptance still follows its contract |
Should every CLOSE_WAIT socket be forcibly reset?
Not as an unexplained repair. Investigate why the application has not completed its local close after the peer's FIN, using the implementation documentation and approved operational procedure.
Does reconnecting establish the earlier command's outcome?
No. Reconnection establishes a new transport session. Resolve the earlier transaction using application evidence and its approved reconciliation policy.
5. Recommended related solutions
Use the networking page for endpoint and capture requirements. Use industrial automation and control scoping when command semantics, retries and operator status must be coordinated across controllers and supervisory software.
For a project quotation, send a sanitised sequence trace, protocol/version details and the required command-outcome policy. Ask for an acceptance plan that covers complete replies, incomplete replies and uncertain execution separately. Device or software support remains subject to the confirmed implementation scope.
Technical reference: RFC 9293, closing and half-closed connections, section 3.6.
Need help with your application?
Send the exact equipment and interface versions, the required outcome and a sanitised example. Ask for a confirmed scope and an acceptance check suited to your application.
Phone: 1800 560 854
.png)


