Repository navigation
Keep the RTU frame after a skipped frame for another device. - #3112
Merged
janiversen merged 2 commits intoDec 4, 2026
Merged
Conversation
FramerRTU.decode() returned the whole buffer length on success, so when handleFrame() skipped a frame for another device, the frame after it was consumed too. decode() now returns the frame length, and handleFrame() still drops whatever follows the frame it uses. After a skipped frame the rest is kept only if it starts with the expected device id, so a stray byte there is still dropped. The CRC failure path is unchanged and still drops the whole buffer. Fixes pymodbus-dev#3110. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
janiversen
requested changes
Dec 3, 2026
| return used_len + size, dev_id, 0, data[used_len + 1 : crc_start] | ||
| return 0, 0, 0, self.EMPTY | ||
|
|
||
| def handleFrame( |
Collaborator
There was a problem hiding this comment.
This do not belong in rtu.py it is handled in base.py and are common for all frames.
Contributor
Author
There was a problem hiding this comment.
Thanks, makes sense. I removed the handleFrame() override in 0029572, the skipping is left to base.py now. The only change in rtu.py is in decode(): it returns the frame length instead of the whole buffer, and still takes a tail that is too short to be another frame (the stray 0x00 from #2664), so test_handleFrame2 keeps passing unchanged.
Drop the handleFrame() override in rtu.py, the skipping is handled in base.py. decode() returns the frame length, and takes the rest of the buffer too when it is too short to be another frame (stray byte after the frame, pymodbus-dev#2664). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
janiversen
pushed a commit
that referenced
this pull request
Dec 4, 2026
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.
Fixes #3110.
Checked on dev (080cf3a): the repro from the issue still loses device 2's response.
FramerRTU.decode()returns the whole buffer length on success, so whenhandleFrame()skips a frame for another device withcontinue, the frame behind it is consumed too.decode()now returns the frame length (used_len + size, the size is known there and the CRC matched), sohandleFrame()in base.py can skip a frame and still see the next one. If what is left after the frame is too short to be another frame,decode()takes it too, so a stray byte after the frame (#2664,test_handleFrame2) is still dropped like before. The CRC failure path is unchanged: the frame end isn't known there, so the whole buffer still goes.Tests:
test_rtu_skip_frame_for_other_deviceand a "double good crc" RTU case intest_decode_complicatedfail on dev and pass here.test_bad_file_record_request_for_framer_rtucovers the decode error path with a stray byte. Fullpytest --covis at 100%, and codespell, ruff, pylint and zuban are clean.#3068 changes these lines in
rtu.pytoo, so whichever lands second needs a small merge.