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

Delay callback_disconnected() until reconnect_delay_max. #2210

Merged
merged 1 commit into from
May 30, 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
9 changes: 5 additions & 4 deletions pymodbus/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,11 @@ async def do_reconnect(self) -> None:
await asyncio.sleep(self.reconnect_delay_current)
if await self.connect():
break
self.reconnect_delay_current = min(
2 * self.reconnect_delay_current,
self.comm_params.reconnect_delay_max,
)
self.reconnect_delay_current = 2 * self.reconnect_delay_current
if self.reconnect_delay_current > self.comm_params.reconnect_delay_max:
self.callback_disconnected(Exception("Retry connect timeout."))
self.reconnect_delay_current = self.comm_params.reconnect_delay_max
break
except asyncio.CancelledError:
pass
self.reconnect_task = None
Expand Down
4 changes: 2 additions & 2 deletions test/transport/test_reconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ async def test_multi_reconnect_call(self, client):
assert client.reconnect_delay_current == client.comm_params.reconnect_delay * 2
await asyncio.sleep(client.reconnect_delay_current * 1.8)
assert client.call_create.call_count == 3
assert client.reconnect_delay_current == client.comm_params.reconnect_delay_max
assert client.reconnect_delay_current >= client.comm_params.reconnect_delay_max
await asyncio.sleep(client.reconnect_delay_current * 1.8)
assert client.call_create.call_count >= 4
assert client.call_create.call_count >= 3
assert client.reconnect_delay_current == client.comm_params.reconnect_delay_max
client.close()

Expand Down