fix: gcConnOnError

This commit is contained in:
Paul 2023-04-10 15:28:36 +02:00
parent 8b617a8f9f
commit 77919b208f
2 changed files with 7 additions and 5 deletions

View File

@ -43,9 +43,10 @@ func WelcomeAgents(ws *websocket.Conn, welcome WSWelcome, t string) {
}
}
func gcConn(conn *websocket.Conn) (err error) {
func gcConnOnError(ws *websocket.Conn) (err error) {
for index, value := range LISTENERS {
if value.ConnectionPS == conn || value.ConnectionRR == conn {
if value.ConnectionPS == ws || value.ConnectionRR == ws {
ws.Close()
delete(LISTENERS, index)
}
}

View File

@ -50,12 +50,13 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
switch apievent.MsgType {
case "bootstrap":
log.Printf("bootstrap: %s\n", apievent.Hostname)
for index, value := range LISTENERS {
if index != apievent.Hostname {
err = websocket.Message.Send(value.ConnectionPS, msg)
if err != nil {
log.Println(err)
gcConn(ws)
gcConnOnError(ws)
}
}
}
@ -73,7 +74,7 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
err = websocket.Message.Send(value.ConnectionPS, msg)
if err != nil {
log.Println(err)
gcConn(ws)
gcConnOnError(ws)
}
}
log.Printf("ws: Inserted event")
@ -82,7 +83,7 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
err = websocket.Message.Send(value.ConnectionPS, msg)
if err != nil {
log.Println(err)
gcConn(ws)
gcConnOnError(ws)
}
}
default: