added conn close on ping call
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Paul 2023-12-26 13:15:11 +01:00
parent 583742eef6
commit 5858b1398f
2 changed files with 16 additions and 1 deletions

View File

@ -33,6 +33,7 @@ func HandleWSPS(c *echo.Context, cfg *config.Config) (err error) {
err = websocket.Message.Receive(ws, "OK") err = websocket.Message.Receive(ws, "OK")
if err != nil { if err != nil {
log.Printf("disconnect: %s (from pubsub channel)\n", welcome.Hostname) log.Printf("disconnect: %s (from pubsub channel)\n", welcome.Hostname)
ws.Close()
} }
for { for {

View File

@ -57,6 +57,7 @@ func HandleWSRR(c *echo.Context, cfg *config.Config) error {
err = websocket.Message.Send(value.(*connectionInfo).ConnectionPS, msg) err = websocket.Message.Send(value.(*connectionInfo).ConnectionPS, msg)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
ws.Close()
gcConnOnError(ws) gcConnOnError(ws)
} }
} }
@ -77,6 +78,7 @@ func HandleWSRR(c *echo.Context, cfg *config.Config) error {
err = websocket.Message.Send(value.(*connectionInfo).ConnectionPS, msg) err = websocket.Message.Send(value.(*connectionInfo).ConnectionPS, msg)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
ws.Close()
gcConnOnError(ws) gcConnOnError(ws)
} }
} }
@ -89,19 +91,31 @@ func HandleWSRR(c *echo.Context, cfg *config.Config) error {
err = websocket.Message.Send(value.(*connectionInfo).ConnectionPS, msg) err = websocket.Message.Send(value.(*connectionInfo).ConnectionPS, msg)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
ws.Close()
gcConnOnError(ws) gcConnOnError(ws)
} }
} }
return true return true
}) })
case "ping": case "ping":
log.Printf("ping: %s\n", apievent.Hostname) listeners.Range(func(index, value interface{}) bool {
if index == apievent.Hostname && value.(*connectionInfo).ConnectionPS != nil {
err = websocket.Message.Send(value.(*connectionInfo).ConnectionPS, msg)
if err != nil {
log.Println(err)
ws.Close()
gcConnOnError(ws)
}
}
return true
})
default: default:
} }
err = websocket.Message.Send(ws, "OK") err = websocket.Message.Send(ws, "OK")
if err != nil { if err != nil {
log.Println(err) log.Println(err)
gcConnOnError(ws)
} }
} }
}).ServeHTTP((*c).Response(), (*c).Request()) }).ServeHTTP((*c).Response(), (*c).Request())