Skip to content

Commit

Permalink
fix: prevent panic on late message after unsubscribed (shurcooL#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
sermojohn authored Mar 8, 2023
1 parent aa8b2bc commit 3bcda95
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ func (sc *SubscriptionContext) GetSubscription(id string) *Subscription {
if sc.subscriptions == nil {
return nil
}
sub, _ := sc.subscriptions[id]
sub, found := sc.subscriptions[id]
if !found {
return nil
}
return &sub
}

Expand Down Expand Up @@ -617,6 +620,9 @@ func (sc *SubscriptionClient) Run() error {
}

sub := sc.context.GetSubscription(message.ID)
if sub == nil {
sub = &Subscription{}
}
go sc.protocol.OnMessage(sc.context, *sub, message)
}
}
Expand Down
3 changes: 3 additions & 0 deletions subscription_graphql_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func (gws *graphqlWS) OnMessage(ctx *SubscriptionContext, subscription Subscript
Data *json.RawMessage
Errors Errors
}
if subscription.handler == nil {
return
}

err := json.Unmarshal(message.Payload, &out)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions subscriptions_transport_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func (stw *subscriptionsTransportWS) OnMessage(ctx *SubscriptionContext, subscri
Data *json.RawMessage
Errors Errors
}
if subscription.handler == nil {
return
}

err := json.Unmarshal(message.Payload, &out)
if err != nil {
Expand Down

0 comments on commit 3bcda95

Please sign in to comment.