Add reconnect logic to WebsocketService in the event of ConnectionClosedError
This commit is contained in:
@@ -138,9 +138,18 @@ class WebsocketService(ABC):
|
|||||||
logger.debug(f"{self} connection closed normally: {e}")
|
logger.debug(f"{self} connection closed normally: {e}")
|
||||||
break
|
break
|
||||||
except ConnectionClosedError as e:
|
except ConnectionClosedError as e:
|
||||||
# Error closure, don't retry
|
# Connection closed with error (e.g., no close frame received/sent)
|
||||||
logger.warning(f"{self} connection closed, but with an error: {e}")
|
# This often indicates network issues, server problems, or abrupt disconnection
|
||||||
break
|
message = f"{self} connection closed, but with an error: {e}"
|
||||||
|
logger.warning(message)
|
||||||
|
|
||||||
|
if self._reconnect_on_error:
|
||||||
|
success = await self._try_reconnect(report_error=report_error)
|
||||||
|
if not success:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
await report_error(ErrorFrame(message))
|
||||||
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
message = f"{self} error receiving messages: {e}"
|
message = f"{self} error receiving messages: {e}"
|
||||||
logger.error(message)
|
logger.error(message)
|
||||||
|
|||||||
Reference in New Issue
Block a user