Skip to content

Correct #2501 #2504

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

Merged
merged 5 commits into from
Dec 14, 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
5 changes: 2 additions & 3 deletions pymodbus/transaction/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ async def execute(self, no_response_expected: bool, request: ModbusPDU) -> Modbu
return response
except asyncio.exceptions.TimeoutError:
count_retries += 1
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 All @@ -191,7 +190,7 @@ def callback_data(self, data: bytes, addr: tuple | None = None) -> int:
used_len, pdu = self.framer.processIncomingFrame(self.trace_packet(False, data))
except ModbusIOException as exc:
if self.is_server:
self.response_future.set_result((None, addr, exc))
Log.info(str(exc))
return len(data)
raise exc
if pdu:
Expand Down
3 changes: 2 additions & 1 deletion test/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ async def test_custom_msg(
if use_comm != "tcp" or use_framer != "socket":
return
assert mock_server
await main_custom_client(port=use_port, host=use_host)
with pytest.raises(asyncio.CancelledError):
await main_custom_client(port=use_port, host=use_host)

async def test_payload(self, mock_clc, mock_cls):
"""Test server/client with payload."""
Expand Down