From 01a9e83f084b05629e5852b6a220d218c0ba1f05 Mon Sep 17 00:00:00 2001 From: grossmj Date: Wed, 8 Dec 2021 00:00:54 +1030 Subject: [PATCH] Ignore OSError when closing websocket --- gns3server/api/routes/compute/notifications.py | 6 ++++-- gns3server/api/routes/controller/notifications.py | 5 ++++- gns3server/api/routes/controller/projects.py | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gns3server/api/routes/compute/notifications.py b/gns3server/api/routes/compute/notifications.py index 7bc0eb5e..621107a7 100644 --- a/gns3server/api/routes/compute/notifications.py +++ b/gns3server/api/routes/compute/notifications.py @@ -78,8 +78,10 @@ async def notification_ws(websocket: WebSocket) -> None: except WebSocketException as e: log.warning(f"Error while sending to controller event to WebSocket client: {e}") finally: - await websocket.close() - + try: + await websocket.close() + except OSError: + pass # ignore OSError: [Errno 107] Transport endpoint is not connected if __name__ == "__main__": diff --git a/gns3server/api/routes/controller/notifications.py b/gns3server/api/routes/controller/notifications.py index 624a2f80..2618efae 100644 --- a/gns3server/api/routes/controller/notifications.py +++ b/gns3server/api/routes/controller/notifications.py @@ -72,4 +72,7 @@ async def controller_ws_notifications( except WebSocketException as e: log.warning(f"Error while sending to controller event to WebSocket client: {e}") finally: - await websocket.close() + try: + await websocket.close() + except OSError: + pass # ignore OSError: [Errno 107] Transport endpoint is not connected diff --git a/gns3server/api/routes/controller/projects.py b/gns3server/api/routes/controller/projects.py index 4050b24b..3f855223 100644 --- a/gns3server/api/routes/controller/projects.py +++ b/gns3server/api/routes/controller/projects.py @@ -271,7 +271,10 @@ async def project_ws_notifications( except WebSocketException as e: log.warning(f"Error while sending to project event to WebSocket client: {e}") finally: - await websocket.close() + try: + await websocket.close() + except OSError: + pass # ignore OSError: [Errno 107] Transport endpoint is not connected if project.auto_close: # To avoid trouble with client connecting disconnecting we sleep few seconds before checking # if someone else is not connected