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)