Skip to content

Commit

Permalink
Improve isCloseError by unwrapping EOFs (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrks authored Oct 17, 2023
1 parent f184aec commit e4a5183
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package blip

import (
gocontext "context"
"errors"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -327,12 +328,14 @@ func includesProtocol(header string, protocols []string) (string, bool) {

// isCloseError returns true if the given error is expected on a websocket close (i.e. io.EOF, WS 1000, 1001, 1005, ...)
func isCloseError(err error) bool {
if err == io.EOF {
// net package library returned EOF for close (it had no support for close handshakes)
if errors.Is(err, io.EOF) {
// - x/net/websocket returned EOF for close (it had no support for close handshakes or wrapped errors)
// - nhooyr/websocket occasionally wraps EOFs with other errors (e.g. "failed to get reader: failed to read frame header: EOF")
return true
}
// The following status codes are mostly expected for clients closing a connection,
// either cleanly (1000, 1001) or abruptly (1005)... Not much cause for concern.

// The following status codes are expected for clients closing a connection,
// either cleanly (1000, 1001) or abruptly (1005)...
switch websocket.CloseStatus(err) {
case websocket.StatusNormalClosure,
websocket.StatusGoingAway,
Expand Down

0 comments on commit e4a5183

Please sign in to comment.