Mercurial > libervia-web
diff libervia/server/websockets.py @ 1513:ff95501abe74
server (websocket): don't crash when a force-close is failing
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 22 May 2023 11:57:49 +0200 |
parents | 106bae41f5c8 |
children |
line wrap: on
line diff
--- a/libervia/server/websockets.py Mon May 22 11:57:49 2023 +0200 +++ b/libervia/server/websockets.py Mon May 22 11:57:49 2023 +0200 @@ -104,10 +104,13 @@ session.touch() session_data = session.getComponent(session_iface.IWebSession) if session_data.ws_socket is not None: - log.warning("Session socket is already set, force closing it") - session_data.ws_socket.send( - "force_close", {"reason": "duplicate connection detected"} - ) + log.warning(f"Session socket is already set {session_data.ws_socket=} {self=}], force closing it") + try: + session_data.ws_socket.send( + "force_close", {"reason": "duplicate connection detected"} + ) + except Exception as e: + log.warning(f"Can't force close old connection: {e}") session_data.ws_socket = self self.__session = session_data self.__profile = session_data.profile or C.SERVICE_PROFILE