Skip to content

Commit de37bea

Browse files
authored
gracefully handle connection failed errors during capability registration (#38)
* register.py: gracefully handle connection errors on capability registration
1 parent b044079 commit de37bea

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pytrickle/utils/register.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,27 @@ async def _make_registration_request(self, orch_url: str, orch_secret: str, regi
6161
if resp.status == 200:
6262
self.logger.info("Capability registered successfully")
6363
return urlparse(register_req["url"])
64-
elif resp.status_code == 400:
64+
elif resp.status == 400:
6565
self.logger.error("Orchestrator secret incorrect")
6666
return False
6767
else:
6868
self.logger.warning(f"Register attempt {attempt} failed: {resp.status} {resp.text}")
6969

70+
except aiohttp.ClientConnectorError as e:
71+
# Handle connect call failed without raising
72+
self.logger.warning(f"Register attempt {attempt} failed to connect: {e}")
73+
except asyncio.TimeoutError as e:
74+
self.logger.warning(f"Register attempt {attempt} timed out: {e}")
7075
except aiohttp.ClientError as e:
71-
self.logger.warning(f"Register attempt {attempt} failed with exception: {e}")
76+
self.logger.warning(f"Register attempt {attempt} failed with client error: {e}")
77+
except Exception as e:
78+
# Ensure unexpected errors don't bubble up and fail startup
79+
self.logger.error(f"Register attempt {attempt} failed with unexpected exception: {e}")
7280

7381
if attempt < max_retries:
7482
await asyncio.sleep(delay)
7583
else:
76-
self.logger.error("All registration retries failed")
84+
self.logger.warning("All registration retries failed")
7785
return False
7886

7987
return False

0 commit comments

Comments
 (0)