Repository navigation
Close the TCP connection instead of sending a disconnect request - #987
Merged
Merged
Conversation
A CP 343-1 kept the connection's resource after disconnect() even with the DR addressed to its reference (#979): the capture shows our FIN 7 us after the DR and the CP answering both with a reset, never with a DC. disconnect() now waits up to one second for a DC, or for the peer to close or reset the connection, before closing the socket, in both clients. The DR also carried a zero byte after its header, outside the length indicator. Class 0 allows no user data in a DR, so it is dropped. Refs #972. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gijzelaerr
force-pushed
the
fix/disconnect-close-sequence
branch
from
November 11, 2026 13:41
488de24 to
db0747e
Compare
Merges master and reworks the fix after the third capture in #972: with the wait for a disconnect confirm in place, the CP 343-1 still answered the COTP disconnect request with a reset and kept the connection. RFC 1006 releases a connection by closing the TCP connection. disconnect() now sends no disconnect request: it closes its sending side, waits up to DISCONNECT_CLOSE_TIMEOUT (1 s, and at most the connection timeout) for the peer to close its own, and then closes the socket. Both clients.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 19, 2026
Merged
…rmation The entry sat under 3.6.0 after merging master, which does not contain this change. The reporter confirmed in #972 that a CP 343-1 now releases the connection. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #972. A CP 343-1 keeps a connection resource after each
disconnect(), until the PLC restarts.Confirmed by the reporter on 20 November: on a CPU 313C behind a CP 343-1 the connection count went to 2 and back to 1 with this branch. The S7-314 has not been re-tested with this version.
What the captures show
Three captures from the reporter, each with a different version of our close sequence:
So the CP 343-1 rejects the disconnect request itself.
Change, in both clients
disconnect()no longer sends a COTP disconnect request. It closes its sending side of the TCP connection (FIN), waits up toDISCONNECT_CLOSE_TIMEOUT(1 s, and at most the connection timeout) for the peer to close its own, and then closes the socket.Two reasons to expect this is the right release:
TSnap7Peer::PeerDisconnect()callsisoDisconnect(true), the "only TCP disconnection" path that sends no disconnect request.The peer reference from #979 is still parsed; nothing sends it any more.
Not covered
disconnect()andPartner.stop()take up to one second against a peer that does not close its side. Two partners in one process do exactly that, sotests/test_partner.pyshortens the wait with a fixture; without it the partner tests take 22 s instead of 7 s.Testing
disconnect()returns as soon as the peer closes, a silent peer is bounded by the timeout, data in flight is discarded, and the socket is closed when the shutdown fails.