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

Fix asyncio.CancelledError on timeout #2503

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 2 additions & 3 deletions pymodbus/transaction/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,17 @@ async def execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbu
self.response_future, timeout=self.comm_params.timeout_connect
)
self.count_no_responses = 0
self.response_future = asyncio.Future()
return response
except asyncio.exceptions.TimeoutError:
count_retries += 1
finally:
self.response_future = asyncio.Future()
if self.count_no_responses >= self.accept_no_response_limit:
self.connection_lost(asyncio.TimeoutError("Server not responding"))
raise ModbusIOException(
f"ERROR: No response received of the last {self.accept_no_response_limit} request, CLOSING CONNECTION."
)
self.count_no_responses += 1
self.response_future = asyncio.Future()
txt = f"No response received after {self.retries} retries, continue with next request"
Log.error(txt)
raise ModbusIOException(txt)
Expand All @@ -178,7 +178,6 @@ def callback_connected(self) -> None:
"""Call when connection is succcesfull."""
self.count_no_responses = 0
self.next_tid = 0
self.response_future = asyncio.Future()
self.trace_connect(True)

def callback_disconnected(self, exc: Exception | None) -> None:
Expand Down