Skip to content

Commit

Permalink
stop reconnecting websocket connection after the context was canceled
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Feb 10, 2025
1 parent 690fee7 commit cf325bd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/hasura/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
POSTGRES_PASSWORD: postgrespassword

hasura:
image: hasura/graphql-engine:v2.16.1.cli-migrations-v3
image: hasura/graphql-engine:v2.45.1.cli-migrations-v3
depends_on:
- "postgres"
ports:
Expand Down
12 changes: 10 additions & 2 deletions subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,17 @@ func (sc *SubscriptionContext) init(parentContext context.Context) error {
sc.cancel = cancel

return nil
} else {
_ = conn.Close()
}

_ = conn.Close()
}

cancel()

if errors.Is(err, context.Canceled) {
return err
}

if sc.client.retryTimeout > 0 && now.Add(sc.client.retryTimeout).Before(time.Now()) {
sc.OnDisconnected()

Expand Down Expand Up @@ -1094,6 +1098,10 @@ func (sc *SubscriptionClient) RunWithContext(ctx context.Context) error {
// the client also automatically retries the connection.
subContext, err := sc.initNewSession(ctx)
if err != nil {
if errors.Is(err, context.Canceled) {
return nil
}

return err
}

Expand Down

0 comments on commit cf325bd

Please sign in to comment.