bitbake: asyncrpc: Handle websockets exceptions

The websockets library throws a number of exceptions which are currently
not caught leading to unhandled exceptions in the idle loop.

Fix this by catching them and reexposing them as a `ConnectionError`
which is the exception expected by users of `asyncrpc`.

(Bitbake rev: 41d62911a480283287265fe063696d2acd5904aa)

Signed-off-by: Philip Lorenz <philip.lorenz@bmw.de>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Philip Lorenz 2024-12-30 13:35:47 +01:00 committed by Richard Purdie
parent f003bd9bda
commit d60c48153d

View File

@ -112,11 +112,16 @@ class AsyncClient(object):
)
async def connect_sock():
websocket = await websockets.connect(
uri,
ping_interval=None,
open_timeout=self.timeout,
)
try:
websocket = await websockets.connect(
uri,
ping_interval=None,
open_timeout=self.timeout,
)
except asyncio.exceptions.TimeoutError:
raise ConnectionError("Timeout while connecting to websocket")
except (OSError, websockets.InvalidHandshake, websockets.InvalidURI) as exc:
raise ConnectionError(f"Could not connect to websocket: {exc}") from exc
return WebsocketConnection(websocket, self.timeout)
self._connect_sock = connect_sock