From 455dbd8a0ccf045f89dc9459330ec9e65a7c2a11 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Mon, 26 Oct 2020 02:34:11 +0000 Subject: [PATCH] sending close frame from client i think --- internal/server/server.go | 6 +++++- internal/wire/client.go | 14 ++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) 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 } } }