From a226fe8de120a73e73751d06d632d1983198354e Mon Sep 17 00:00:00 2001 From: Aleksei Korotin <277992+korotin@users.noreply.github.com> Date: Tue, 28 Nov 2023 21:10:05 +0500 Subject: [PATCH] Fixed goroutine leak in subscriptions (#626) --- subscriptions.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/subscriptions.go b/subscriptions.go index 91e84c0d8..11b2398a0 100644 --- a/subscriptions.go +++ b/subscriptions.go @@ -76,10 +76,14 @@ func (s *Schema) subscribe(ctx context.Context, queryString string, operationNam responses := r.Subscribe(ctx, res, op) c := make(chan interface{}) go func() { + Loop: for resp := range responses { - c <- &Response{ - Data: resp.Data, - Errors: resp.Errors, + select { + case c <- &Response{Data: resp.Data, Errors: resp.Errors}: + continue + + case <-ctx.Done(): + break Loop } } close(c)