Skip to content

fix: resynchronize the client receive buffer - #361

Open
Barneey96 wants to merge 4 commits into
Cloud-Automation:v5.0-devfrom
Barneey96:fix/resync-response-buffer
Open

Barneey96 wants to merge 4 commits into
Cloud-Automation:v5.0-devfrom
Barneey96:fix/resync-response-buffer

Conversation

@Barneey96

@Barneey96 Barneey96 commented Sep 15, 2026

Copy link
Copy Markdown

The fix verifies the RTU CRC during parsing and exposes a corrupted flag mirroring the existing ModbusRTURequest behaviour, so a misparse realigns the buffer instead of consuming it. It also gives each transport a real resynchronization step: Modbus/TCP skips a complete-but-unparsable frame whole using the exact length in its MBAP header and drops a single byte when the header itself is implausible, while Modbus/RTU drops a byte whenever the function code cannot begin any response body or the CRC fails. Recovery from a desynchronizing frame falls from 25 request timeouts to 1 on TCP and from 38 to 1 on RTU, and the same 256 stray-byte cases now all return the correct reading immediately, with the buffer-size limit retained as a backstop for the one case nothing can prove — a frame stalled behind a valid function code.

@Barneey96
Barneey96 marked this pull request as ready for review September 15, 2026 08:58
@stefanpoeter

Copy link
Copy Markdown
Member

Thanks a lot, i will review this as soon as I can. This seems to be a of a patch character so can you bump the patch version in package.json from 5.0.0 to 5.0.1.

@Barneey96

Copy link
Copy Markdown
Author

Thanks a lot, i will review this as soon as I can. This seems to be a of a patch character so can you bump the patch version in package.json from 5.0.0 to 5.0.1.

Thank you, sure please take your time. I'm testing in the meanwhile with multiple ModbusTCP systems - so far looks great, but I'm open for feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants