Fix ws to prevent disconnect bug

node.py and session.py
This commit is contained in:
jerlendds
2024-01-03 12:48:13 -07:00
parent 76339e4b37
commit 231953956c
2 changed files with 28 additions and 22 deletions

View File

@@ -381,26 +381,27 @@ async def active_graph_inquiry(
websocket.send({"action": "error"})
for cid, ws in graph_users.items():
async for event in ws.iter_json():
try:
await run_user_graph_event(
event=event,
send_json=ws.send_json,
uuid=active_inquiry.uuid
)
except OBPluginError as e:
await ws.send_json({"action": "error", "detail": f"{e}"})
await ws.send_json({"action": "isLoading", "detail": False })
log.error(e)
except (WebSocketException, ConnectionClosedError) as e:
log.error("Exception inside node.active_project")
log.error(e)
await ws.send_json({"action": "isLoading", "detail": False })
await ws.close()
del graph_users[cid]
except WebSocketDisconnect as e:
log.info(f"disconnect! {cid}")
del graph_users[cid]
while True:
try:
async for event in ws.iter_json():
await run_user_graph_event(
event=event,
send_json=ws.send_json,
uuid=active_inquiry.uuid
)
except OBPluginError as e:
await ws.send_json({"action": "error", "detail": f"{e}"})
await ws.send_json({"action": "isLoading", "detail": False })
log.error(e)
except (WebSocketException, ConnectionClosedError) as e:
log.error("Exception inside node.active_project")
log.error(e)
await ws.send_json({"action": "isLoading", "detail": False })
await ws.close()
del graph_users[cid]
except (WebSocketDisconnect, RuntimeError) as e:
log.info(f"disconnect! {cid}")
del graph_users[cid]
@router.get("/refresh")

View File

@@ -1,9 +1,14 @@
import os
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.core.config import settings
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True)
DB_POOL_SIZE = int(os.getenv("DB_POOL_SIZE", "100"))
WEB_CONCURRENCY = int(os.getenv("WEB_CONCURRENCY", "4"))
POOL_SIZE = max(DB_POOL_SIZE // WEB_CONCURRENCY, 5)
engine = create_engine(settings.SQLALCHEMY_DATABASE_URI, pool_size=POOL_SIZE, max_overflow=0, pool_pre_ping=True)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)