Skip to content

Commit

Permalink
Add default connect retries
Browse files Browse the repository at this point in the history
  • Loading branch information
xjules committed Dec 30, 2024
1 parent 913bc39 commit cdd1292
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/_ert/forward_model_runner/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ClientConnectionError(Exception):
class Client:
DEFAULT_MAX_RETRIES = 10
DEFAULT_ACK_TIMEOUT = 5
DEFAULT_CONNECT_RETRIES = 1

def __init__(
self,
Expand Down Expand Up @@ -83,7 +84,7 @@ async def connect(self) -> None:
await self._term_receiver_task()
self._receiver_task = asyncio.create_task(self._receiver())
try:
await self.send(CONNECT_MSG, retries=1)
await self.send(CONNECT_MSG, retries=self.DEFAULT_CONNECT_RETRIES)
except ClientConnectionError:
await self._term_receiver_task()
self.term()
Expand Down Expand Up @@ -136,13 +137,14 @@ async def send(self, message: str | bytes, retries: int | None = None) -> None:
self.term()
raise

retries -= 1
if retries > 0:
logger.info(f"Retrying... ({retries} attempts left)")
await asyncio.sleep(backoff)
# this call is idempotent
self.socket.disconnect(self.url)
self.socket.connect(self.url)
backoff = min(backoff * 2, 10) # Exponential backoff
retries -= 1
raise ClientConnectionError(
f"{self.dealer_id} Failed to send {message!r} after retries!"
)

0 comments on commit cdd1292

Please sign in to comment.