diff --git a/common/metric_types.py b/common/metric_types.py index 0554f7a..355f4d4 100644 --- a/common/metric_types.py +++ b/common/metric_types.py @@ -92,11 +92,18 @@ async def _collect_ws_data(): finally: if websocket: try: - # Shield cleanup from cancellation to ensure proper resource cleanup await asyncio.shield(self.unsubscribe(websocket)) + except asyncio.CancelledError: + logging.info("Unsubscribe completed despite cancellation") + except Exception as e: + logging.warning(f"Error during unsubscribe (non-critical): {e!s}") + + try: await asyncio.shield(websocket.close()) + except asyncio.CancelledError: + logging.info("WebSocket close completed despite cancellation") except Exception as e: - logging.error(f"Error closing websocket: {e!s}") + logging.warning(f"Error closing websocket (non-critical): {e!s}") class HttpMetric(BaseMetric):