Skip to content

Commit

Permalink
#1103: Fixing broken pipe errors (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kannav02 authored Oct 26, 2024
1 parent fb36991 commit 7e04547
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/server/websocketServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ func (s *WebsocketServer) WebsocketHandler(w http.ResponseWriter, r *http.Reques

// closing handshake
defer func() {
_ = conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "close 1000 (normal)"))
closeErr := conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "close 1000 (normal)"))
if closeErr != nil {
slog.Debug("Error during closing handshake", slog.Any("error", closeErr))
}
conn.Close()
}()

Expand All @@ -131,9 +134,10 @@ func (s *WebsocketServer) WebsocketHandler(w http.ResponseWriter, r *http.Reques
if err != nil {
// acceptable close errors
errs := []int{websocket.CloseNormalClosure, websocket.CloseGoingAway, websocket.CloseAbnormalClosure}
if !websocket.IsCloseError(err, errs...) {
slog.Warn("failed to read message from client", slog.Any("error", err))
if websocket.IsCloseError(err, errs...) {
break
}
slog.Error("Error reading message", slog.Any("error", err))
break
}

Expand Down

0 comments on commit 7e04547

Please sign in to comment.