diff --git a/pymodbus/transport/transport.py b/pymodbus/transport/transport.py index 265d98e1d..e6d32cb9e 100644 --- a/pymodbus/transport/transport.py +++ b/pymodbus/transport/transport.py @@ -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 diff --git a/test/transport/test_reconnect.py b/test/transport/test_reconnect.py index 31d9960c6..e97a62119 100644 --- a/test/transport/test_reconnect.py +++ b/test/transport/test_reconnect.py @@ -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()