Skip to content

Commit

Permalink
Do not handle network error in SetCloseHandler()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nak3 authored and AlexVulaj committed Jan 22, 2024
1 parent 0f0acef commit 9a21405
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9a21405

Please sign in to comment.