Skip to content

Commit

Permalink
Revert "Delay callback_disconnected() until reconnect_delay_max. (#2210
Browse files Browse the repository at this point in the history
…)"

This reverts commit 45a998b.
  • Loading branch information
janiversen committed May 31, 2024
1 parent 45a998b commit 450b96f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
9 changes: 4 additions & 5 deletions pymodbus/transport/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,10 @@ async def do_reconnect(self) -> None:
await asyncio.sleep(self.reconnect_delay_current)
if await self.connect():
break
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
self.reconnect_delay_current = min(
2 * self.reconnect_delay_current,
self.comm_params.reconnect_delay_max,
)
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 >= 3
assert client.call_create.call_count >= 4
assert client.reconnect_delay_current == client.comm_params.reconnect_delay_max
client.close()

Expand Down

0 comments on commit 450b96f

Please sign in to comment.