closeConnection closes a WebSocket connection
(wsConn *WebSocketConnection)
| 486 | |
| 487 | // closeConnection closes a WebSocket connection |
| 488 | func (h *WebSocketHandler) closeConnection(wsConn *WebSocketConnection) { |
| 489 | h.mu.Lock() |
| 490 | delete(h.connections, wsConn.ID) |
| 491 | h.mu.Unlock() |
| 492 | |
| 493 | // Cancel pending HITL requests for this connection |
| 494 | if h.hitlManager != nil { |
| 495 | h.hitlManager.CancelPendingRequests(wsConn.ID) |
| 496 | } |
| 497 | |
| 498 | wsConn.cancel() |
| 499 | close(wsConn.Send) |
| 500 | |
| 501 | if wsConn.Agent != nil { |
| 502 | h.registry.Unregister((*wsConn.Agent).ID()) |
| 503 | if err := (*wsConn.Agent).Close(); err != nil { |
| 504 | logging.Error(wsConn.ctx, "failed to close agent", map[string]any{ |
| 505 | "error": err.Error(), |
| 506 | }) |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | logging.Info(wsConn.ctx, "websocket.disconnected", map[string]any{ |
| 511 | "connection_id": wsConn.ID, |
| 512 | }) |
| 513 | } |
| 514 | |
| 515 | // GetStats returns WebSocket statistics |
| 516 | func (h *WebSocketHandler) GetStats(c *gin.Context) { |
no test coverage detected