mirror of
https://github.com/fankes/beszel.git
synced 2025-10-19 09:49:28 +08:00
send websocket close message to agent
This commit is contained in:
@@ -100,8 +100,7 @@ func (acr *agentConnectRequest) verifyWsConn(conn *gws.Conn, fpRecords []ws.Fing
|
|||||||
// make sure connection is closed if there is an error
|
// make sure connection is closed if there is an error
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
wsConn.Close()
|
wsConn.Close([]byte(err.Error()))
|
||||||
acr.hub.Logger().Error("WebSocket error", "error", err, "systems", fpRecords)
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@@ -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.
|
// The system will be set as down a few seconds later if the connection is not re-established.
|
||||||
func (sys *System) closeWebSocketConnection() {
|
func (sys *System) closeWebSocketConnection() {
|
||||||
if sys.WsConn != nil {
|
if sys.WsConn != nil {
|
||||||
sys.WsConn.Close()
|
sys.WsConn.Close(nil)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -77,7 +77,7 @@ func (h *Handler) OnMessage(conn *gws.Conn, message *gws.Message) {
|
|||||||
case wsConn.(*WsConn).responseChan <- message:
|
case wsConn.(*WsConn).responseChan <- message:
|
||||||
default:
|
default:
|
||||||
// close if the connection is not expecting a response
|
// 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.
|
// Close terminates the WebSocket connection gracefully.
|
||||||
func (ws *WsConn) Close() {
|
func (ws *WsConn) Close(msg []byte) {
|
||||||
if ws.IsConnected() {
|
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 {
|
select {
|
||||||
case <-time.After(10 * time.Second):
|
case <-time.After(10 * time.Second):
|
||||||
ws.Close()
|
ws.Close(nil)
|
||||||
return gws.ErrConnClosed
|
return gws.ErrConnClosed
|
||||||
case message = <-ws.responseChan:
|
case message = <-ws.responseChan:
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user