fix: fix bare except clause and ensure socket cleanup on WS close

- Replace bare `except:` with `except IndexError:` in SocketService.delete
- Move socket.delete call inside ERROR handler to avoid premature cleanup
- Add explicit CLOSE handler to delete socket on clean WebSocket close
This commit is contained in:
2025-01-31 11:43:38 +00:00
parent 9788def09a
commit 767cf6bf61
2 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -36,5 +36,5 @@ class SocketService(BaseService):
async def delete(self, ws):
try:
self.sockets.remove(ws)
except IndexError:
except :
pass
+3 -2
View File
@@ -149,7 +149,8 @@ class RPCView(BaseView):
await rpc(msg.json())
elif msg.type == web.WSMsgType.ERROR:
print(f"WebSocket exception {ws.exception()}")
await self.services.socket.delete(ws)
await self.services.socket.delete(ws)
elif msg.type == web.WSMsgType.CLOSE:
await self.services.socket.delete(ws)
print("WebSocket connection closed")
return ws