Skip to content

Commit

Permalink
fix: prevents goroutine leak at websocket transport
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcherist committed May 14, 2022
1 parent b8ec51d commit 3f7bf38
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions graphql/handler/transport/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,20 @@ func (c *wsConnection) subscribe(start time.Time, msg *message) {

responses, ctx := c.exec.DispatchOperation(ctx, rc)
for {
response := responses(ctx)
if response == nil {
break
}
// prevents goroutine leak
select {
case <-ctx.Done():
return
default:
{
response := responses(ctx)
if response == nil {
break
}

c.sendResponse(msg.id, response)
c.sendResponse(msg.id, response)
}
}
}

// complete and context cancel comes from the defer
Expand Down

0 comments on commit 3f7bf38

Please sign in to comment.