Skip to content

Commit

Permalink
Improve error handling in AsyncSubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Simeon Miteff committed Jun 13, 2023
1 parent 646324c commit 43af6c2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/client/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"

"github.com/corelight/go-zeek-broker-ws/pkg/encoding"
"github.com/gorilla/websocket"
)

type EventHandler func(topic string, event encoding.Event)
Expand All @@ -29,9 +30,18 @@ func AsyncSubscription(ctx context.Context, broker *Client, hm EventHandler, eh
topic, evt, err := broker.ReadEvent()

if err != nil {
if IsNormalWebsocketClose(err) {
e, ok := err.(*websocket.CloseError) //nolint:errorlint //oh shush
if ok {
// Normal EOF close
if e.Code == websocketNormalEOFCode {
return
}

// Abnormal websocket error, pass to handler then exit
eh(err)
return
}

//nolint:errorlint //oh shush
if opErr, ok := err.(*net.OpError); ok && opErr.Err.Error() == "use of closed network connection" {
return
Expand Down

0 comments on commit 43af6c2

Please sign in to comment.