diff --git a/internal/server/server.go b/internal/server/server.go index 51b30cb..b8b04a8 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -86,7 +86,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { for { t, r, err := conn.NextReader() if err != nil { - s.Error("read error: %v", err) + if websocket.IsCloseError(err, websocket.CloseNormalClosure) { + s.Info("received close frame from client") + } else { + s.Error("read error: %v", err) + } return } diff --git a/internal/wire/client.go b/internal/wire/client.go index ecb15b7..e46d778 100644 --- a/internal/wire/client.go +++ b/internal/wire/client.go @@ -87,6 +87,10 @@ func (c *Client) readLoop(notifications chan<- Response) { for { _, r, err := c.conn.NextReader() if err != nil { + if websocket.IsCloseError(err, websocket.CloseNormalClosure) { + c.Info("received close frame from server") + break + } c.Error("unable to get a reader frame: %v", err) break } @@ -155,18 +159,16 @@ func (c *Client) writeLoop() { case shouldClose := <-c.done: if shouldClose { + c.Info("sending close frame") msg := websocket.FormatCloseMessage(websocket.CloseNormalClosure, "") if err := c.conn.WriteMessage(websocket.CloseMessage, msg); err != nil { c.Error("failed to write close message: %v", err) + } else { + c.Info("sent close frame") } - c.Info("closing connection") - if err := c.conn.Close(); err != nil { - c.Error("failed to close connection: %v", err) - } - c.Info("connection closed") c.conn = nil - return } + return } } }