Skip to content

Commit

Permalink
fix: handle closed error on subscription (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Jan 6, 2024
1 parent 57b21fd commit 48aa45c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"net"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -293,6 +294,9 @@ func (sc *SubscriptionContext) Close() error {

sc.Cancel()

if errors.Is(err, net.ErrClosed) {
return nil
}
return err
}

Expand Down Expand Up @@ -767,7 +771,7 @@ func (sc *SubscriptionClient) Run() error {
var message OperationMessage
if err := conn.ReadJSON(&message); err != nil {
// manual EOF check
if err == io.EOF || strings.Contains(err.Error(), "EOF") || strings.Contains(err.Error(), "connection reset by peer") {
if err == io.EOF || strings.Contains(err.Error(), "EOF") || errors.Is(err, net.ErrClosed) || strings.Contains(err.Error(), "connection reset by peer") {
sc.errorChan <- errRetry
return
}
Expand Down Expand Up @@ -922,7 +926,7 @@ func (sc *SubscriptionClient) close(ctx *SubscriptionContext) (err error) {
continue
}
if sub.status == SubscriptionRunning {
if err := sc.protocol.Unsubscribe(ctx, sub); err != nil {
if err := sc.protocol.Unsubscribe(ctx, sub); err != nil && !errors.Is(err, net.ErrClosed) {
unsubscribeErrors[key] = err
}
}
Expand Down

0 comments on commit 48aa45c

Please sign in to comment.