Correctly handle closing of websocket, whoopsie

This commit is contained in:
Dane Everitt
2019-04-20 15:45:48 -07:00
parent b20bfac36b
commit ebe98aa860
3 changed files with 22 additions and 148 deletions

View File

@@ -43,11 +43,18 @@ func (rt *Router) routeWebsocket(w http.ResponseWriter, r *http.Request, ps http
for {
j := WebsocketMessage{server: s, inbound: true}
if _, _, err := c.ReadMessage(); err != nil {
if !websocket.IsCloseError(err, websocket.CloseNormalClosure, websocket.CloseGoingAway, websocket.CloseServiceRestart) {
zap.S().Errorw("error handling websocket message", zap.Error(err))
}
break
}
// Discard and JSON parse errors into the void and don't continue processing this
// specific socket request. If we did a break here the client would get disconnected
// from the socket, which is NOT what we want to do.
if err := c.ReadJSON(&j); err != nil {
break
continue
}
fmt.Printf("%s received: %s = %s\n", s.Uuid, j.Event, strings.Join(j.Args, " "))