Skip to content

Commit 2e23fb2

Browse files
committed
Flush recv_buffer on cancellation
If asyncio.wait_for is cancelled by the caller we need to clean up the recv_buffer as well.
1 parent 528d70d commit 2e23fb2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

pymodbus/transaction/transaction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ async def execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbu
153153
return response
154154
except asyncio.exceptions.TimeoutError:
155155
count_retries += 1
156+
except asyncio.exceptions.CancelledError:
157+
self.recv_buffer = b""
158+
raise
156159
if self.count_until_disconnect < 0:
157160
self.connection_lost(asyncio.TimeoutError("Server not responding"))
158161
raise ModbusIOException(

0 commit comments

Comments
 (0)