Repository navigation
fix(s7): bound every PLC request with a deadline - #246
Merged
Merged
Conversation
A PLC that accepts the TCP connection and stops answering hung the app without a limit. S7Driver passed no timeout to S7netplus, and the library's ReadTimeout and WriteTimeout do not apply to its async calls, so one stuck read or write held the transport gate. The keep-alive probe queued behind that gate, so link loss was never declared and the reconnect loop never ran. A stuck connect also blocked the reconnect loop and DisconnectAsync, and each ConnectAsync left the previous client open. Each connect attempt and each PDU request now runs on a token that S7Driver cancels after S7Driver.TransportDeadline (5 s). A probe showed that S7netplus 0.20.0 ends connect, read and write on that token. S7netplus splits a block into several PDU requests on one token, so a large array on a slow PLC would pass one shared deadline on a healthy link. The driver therefore sends each block in chunks of one PDU, sized from the negotiated Plc.MaxPDUSize minus the library's request overhead, and each chunk gets its own deadline. Order and content of the bytes on the wire do not change. On the deadline the driver closes the client and throws TimeoutException. The executor reports that exception as PlcCommandFailedError, so a cut-off recipe write is a failed write. Once the gate is released, the driver raises RequestDeadlinePassed, and S7Service calls OnConnectionLost on the thread pool: the poll that passed the deadline must not wait for itself to stop. ConnectAsync closes the old client before it creates a new one. writing_timeout_ms had no reader and now overlaps the deadline, so it is removed from the settings, the shipped configs and the docs. The YAML loader ignores unknown keys, so old configs still load. Refs #181 Co-Authored-By: Claude Opus 5.5 <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.
Problem
No PLC request had a time limit. A PLC that accepts the connection and then stops answering left a connect, read or write hanging forever: the transport gate stayed held, the keep-alive probe queued behind it, so link loss was never declared and the link slot kept its last state. Any flow waiting on that request could not finish.
S7Driver.ConnectAsyncalso replaced its client without closing the old one, so repeated reconnects could use up PLC connection slots.What changed
ReadTimeoutandWriteTimeoutdo nothing for async calls; a cancelled token ends connect, read and write about 20 ms later, and the library then closes the client. The plan's Caveats record it.S7Drivergives every request its own 5 s deadline (TransportDeadline). Block reads and writes are split into chunks of the negotiated PDU size, the library's own split sizes, and each chunk is one call with its own deadline, so a large recipe on a slow link does not time out as one call.ConnectAsynccloses the old client first. A negotiated PDU too small to hold a chunk throws instead of looping.writing_timeout_mssetting is removed from the settings, the shipped configs and the docs. The YAML loader ignores unknown keys, so older configs still load.This is Task 3a of
docs/plans/20261130-recipe-replace-save-exit-safety.md. A timed-out version read on reconnect still turns sync off; Task 3b changes that.Verification
dotnet format --verify-no-changesclean.Refs #181
🤖 Generated with Claude Code