From a2d76f2b7abf6d241eb18d180266fea9f7a7d582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20S=C3=B6derberg?= Date: Sun, 22 Feb 2026 22:01:11 +0100 Subject: [PATCH] Websocket changes --- backend/Dockerfile | 2 +- backend/app/routes/websocket.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index 45e6442..d7f453e 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -14,4 +14,4 @@ COPY ./app ./app RUN mkdir -p /app/data EXPOSE $PORT -CMD ["sh", "-c", "gunicorn -w 4 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:$PORT"] \ No newline at end of file +CMD ["sh", "-c", "gunicorn -w 1 -k uvicorn.workers.UvicornWorker app.main:app --bind 0.0.0.0:$PORT"] \ No newline at end of file diff --git a/backend/app/routes/websocket.py b/backend/app/routes/websocket.py index 4d79899..3de09dc 100644 --- a/backend/app/routes/websocket.py +++ b/backend/app/routes/websocket.py @@ -1,4 +1,6 @@ # backend/app/routes/websocket.py +import asyncio + from fastapi import APIRouter, WebSocket, WebSocketDisconnect from ..core.websocket_manager import manager @@ -11,6 +13,11 @@ async def websocket_endpoint(websocket: WebSocket): await manager.connect(websocket) try: while True: - await websocket.receive_text() + try: + await asyncio.wait_for(websocket.receive_text(), timeout=30.0) + except asyncio.TimeoutError: + await websocket.send_json({"type": "ping"}) except WebSocketDisconnect: manager.disconnect(websocket) + except Exception: + manager.disconnect(websocket)