From f0f3bf001a8153e156d9cd8faef158f359c1ae85 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Wed, 8 Nov 2023 21:00:20 +0900 Subject: [PATCH 1/4] Do not handle network error in SetCloseHandler() The 666c197 added an error handling in `SetCloseHandler()` and peer stops getting `CloseError` when network issue like `write: broken pipe` happens because the close handle returns the error. Hence this patch changes to skip network error handling. --- conn.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index a19e5c4e..a992825b 100644 --- a/conn.go +++ b/conn.go @@ -1159,8 +1159,12 @@ func (c *Conn) SetCloseHandler(h func(code int, text string) error) { h = func(code int, text string) error { message := FormatCloseMessage(code, "") err := c.WriteControl(CloseMessage, message, time.Now().Add(writeWait)) - if err != nil && err != ErrCloseSent { - return err + if err != nil { + if _, ok := err.(net.Error); ok { + return nil + } else if err != ErrCloseSent { + return err + } } return nil } From 8e0711bc91cee677e3159c688e865692ec24b8f3 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Tue, 14 Nov 2023 14:28:33 +0900 Subject: [PATCH 2/4] Do not return error in SetCloseHandler --- conn.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/conn.go b/conn.go index a992825b..e27a971a 100644 --- a/conn.go +++ b/conn.go @@ -1158,14 +1158,7 @@ func (c *Conn) SetCloseHandler(h func(code int, text string) error) { if h == nil { h = func(code int, text string) error { message := FormatCloseMessage(code, "") - err := c.WriteControl(CloseMessage, message, time.Now().Add(writeWait)) - if err != nil { - if _, ok := err.(net.Error); ok { - return nil - } else if err != ErrCloseSent { - return err - } - } + _ = c.WriteControl(CloseMessage, message, time.Now().Add(writeWait)) return nil } } From 731d7a353a6d2219c41fc830687f96c2cfae9561 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Tue, 14 Nov 2023 14:35:25 +0900 Subject: [PATCH 3/4] Print log message --- conn.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index e27a971a..1b78626d 100644 --- a/conn.go +++ b/conn.go @@ -1158,7 +1158,10 @@ func (c *Conn) SetCloseHandler(h func(code int, text string) error) { if h == nil { h = func(code int, text string) error { message := FormatCloseMessage(code, "") - _ = c.WriteControl(CloseMessage, message, time.Now().Add(writeWait)) + err := c.WriteControl(CloseMessage, message, time.Now().Add(writeWait)) + if err != nil { + log.Printf("websocket: discarding close handler error: %v", err) + } return nil } } From 42fd2c03c7c9b4a7747e3e67256a73c74e213907 Mon Sep 17 00:00:00 2001 From: Kenjiro Nakayama Date: Mon, 11 Dec 2023 13:39:50 +0900 Subject: [PATCH 4/4] Revert "Print log message" This reverts commit 6db907caed005e552af68cebc565c86af1579956. --- conn.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/conn.go b/conn.go index 1b78626d..e27a971a 100644 --- a/conn.go +++ b/conn.go @@ -1158,10 +1158,7 @@ func (c *Conn) SetCloseHandler(h func(code int, text string) error) { if h == nil { h = func(code int, text string) error { message := FormatCloseMessage(code, "") - err := c.WriteControl(CloseMessage, message, time.Now().Add(writeWait)) - if err != nil { - log.Printf("websocket: discarding close handler error: %v", err) - } + _ = c.WriteControl(CloseMessage, message, time.Now().Add(writeWait)) return nil } }