send websocket close message to agent

This commit is contained in:
henrygd
2025-07-12 18:49:40 -04:00
parent 4f879ccc66
commit b5d55ead4a
3 changed files with 6 additions and 7 deletions

View File

@@ -100,8 +100,7 @@ func (acr *agentConnectRequest) verifyWsConn(conn *gws.Conn, fpRecords []ws.Fing
// make sure connection is closed if there is an error
defer func() {
if err != nil {
wsConn.Close()
acr.hub.Logger().Error("WebSocket error", "error", err, "systems", fpRecords)
wsConn.Close([]byte(err.Error()))
}
}()

View File

@@ -365,7 +365,7 @@ func (sys *System) closeSSHConnection() {
// The system will be set as down a few seconds later if the connection is not re-established.
func (sys *System) closeWebSocketConnection() {
if sys.WsConn != nil {
sys.WsConn.Close()
sys.WsConn.Close(nil)
}
}

View File

@@ -77,7 +77,7 @@ func (h *Handler) OnMessage(conn *gws.Conn, message *gws.Message) {
case wsConn.(*WsConn).responseChan <- message:
default:
// close if the connection is not expecting a response
wsConn.(*WsConn).Close()
wsConn.(*WsConn).Close(nil)
}
}
@@ -100,9 +100,9 @@ func (h *Handler) OnClose(conn *gws.Conn, err error) {
}
// Close terminates the WebSocket connection gracefully.
func (ws *WsConn) Close() {
func (ws *WsConn) Close(msg []byte) {
if ws.IsConnected() {
ws.conn.WriteClose(1000, nil)
ws.conn.WriteClose(1000, msg)
}
}
@@ -130,7 +130,7 @@ func (ws *WsConn) RequestSystemData(data *system.CombinedData) error {
})
select {
case <-time.After(10 * time.Second):
ws.Close()
ws.Close(nil)
return gws.ErrConnClosed
case message = <-ws.responseChan:
}