Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset receive buffer with send() to avoid bad data spillover. #2343

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pymodbus/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ def send(self, data: bytes, addr: tuple | None = None) -> None:
Log.error("Cancel send, because not connected!")
return
Log.debug("send: {}", data, ":hex")
self.recv_buffer = b""
if self.comm_params.handle_local_echo:
self.sent_buffer += data
if self.comm_params.comm_type == CommType.UDP:
Expand Down
2 changes: 1 addition & 1 deletion test/transport/test_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ async def test_connected_multiple(self, client, server, use_port):

client2.send(test_data)
await asyncio.sleep(0.5)
assert server2_connected.recv_buffer == test2_data + test_data
assert server2_connected.recv_buffer == test_data
client2.close()
server.close()
await asyncio.sleep(0.5)
Expand Down