Skip to content

Commit

Permalink
Don't set_result on completed futures. (#2582)
Browse files Browse the repository at this point in the history
Co-authored-by: jan iversen <jancasacondor@gmail.com>
  • Loading branch information
jameshilliard and janiversen authored Feb 23, 2025
1 parent c55d05b commit 74d1dcf
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pymodbus/transaction/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ async def execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbu
return response
except asyncio.exceptions.TimeoutError:
count_retries += 1
except asyncio.exceptions.CancelledError as exc:
raise ModbusIOException("Request cancelled outside pymodbus.") from exc
if self.count_until_disconnect < 0:
self.connection_lost(asyncio.TimeoutError("Server not responding"))
raise ModbusIOException(
Expand Down Expand Up @@ -195,6 +197,8 @@ def callback_data(self, data: bytes, addr: tuple | None = None) -> int:
raise ModbusIOException(
f"ERROR: request ask for id={self.request_dev_id} but got id={pdu.dev_id}, CLOSING CONNECTION."
)
if self.response_future.done():
raise ModbusIOException(f"received pdu: {pdu:str} without a corresponding request")
self.response_future.set_result(self.last_pdu)
return used_len

Expand Down

0 comments on commit 74d1dcf

Please # to comment.