debug: add detailed logging for terminal WebSocket connections
Deploy Dashboard (Dev) / deploy-dev (push) Successful in 2m35s

This commit is contained in:
Gan, Jimmy
2026-03-12 00:23:23 +08:00
parent e0f432bc39
commit 00b5d362e7
+4 -1
View File
@@ -122,6 +122,7 @@ async def ws_endpoint(websocket: WebSocket, host: str = Query("nas"), token: str
session_id = session_or_code session_id = session_or_code
await websocket.accept() await websocket.accept()
logger.info("WebSocket accepted for %s (user: %s)", host, user.username)
h = HOSTS[host] h = HOSTS[host]
try: try:
@@ -134,6 +135,7 @@ async def ws_endpoint(websocket: WebSocket, host: str = Query("nas"), token: str
), ),
timeout=10.0 timeout=10.0
) )
logger.info("SSH connection established to %s", host)
except asyncio.TimeoutError: except asyncio.TimeoutError:
logger.error("SSH connection to %s timed out after 10s", host) logger.error("SSH connection to %s timed out after 10s", host)
await _release_session(session_id) await _release_session(session_id)
@@ -180,11 +182,12 @@ async def ws_endpoint(websocket: WebSocket, host: str = Query("nas"), token: str
process.stdin.write(data) process.stdin.write(data)
elif "text" in msg and msg["text"]: elif "text" in msg and msg["text"]:
if msg["text"] == "__ping__": if msg["text"] == "__ping__":
logger.debug("Received ping from %s, sending pong", host)
await websocket.send_text("__pong__") await websocket.send_text("__pong__")
continue continue
process.stdin.write(msg["text"].encode()) process.stdin.write(msg["text"].encode())
except Exception as e: except Exception as e:
logger.info("WebSocket receive loop ended for %s: %s", host, e) logger.warning("WebSocket receive loop ended for %s: %s", host, e)
finally: finally:
read_task.cancel() read_task.cancel()
process.close() process.close()