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.
This commit is contained in:
Kenjiro Nakayama 2023-11-08 21:00:20 +09:00 committed by Alex Vulaj
parent 0f0acefeac
commit 9a2140519a
1 changed files with 6 additions and 2 deletions

View File

@ -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
}