fix: explicitly close WebSocket with code 1000 when loops end
When any of the read/write/heartbeat loops ends, we were cancelling remaining tasks but not explicitly closing the WebSocket. This caused the connection to be dropped with 1006 abnormal closure instead of a clean 1000 close. The frontend then reconnected, creating a loop.
This commit is contained in:
@@ -100,6 +100,12 @@ async def terminal_websocket(
|
|||||||
# Cancel remaining tasks
|
# Cancel remaining tasks
|
||||||
for task in pending:
|
for task in pending:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
|
|
||||||
|
# Close WebSocket cleanly to avoid 1006 abnormal closure
|
||||||
|
try:
|
||||||
|
await websocket.close(code=1000)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.error("Terminal session error for instance %s: %s", instance_id, str(exc), exc_info=True)
|
logger.error("Terminal session error for instance %s: %s", instance_id, str(exc), exc_info=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user