From 853df6d2850d05feba56c856f369b1963c1e37de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Thu, 25 Apr 2019 16:48:05 +0300 Subject: [PATCH] store/proxy: properly check if context has ended How the code was before it could happen that we might receive some series from the stream however by the time we'd send them back to the reader, it would not read it anymore since the deadline would have been exceeded. Properly use a `select` here to get out of the goroutine if the deadline has been exceeded. Might potentially fix a problem where we see one goroutine hanging constantly (and thus blocking from work being done): ``` goroutine profile: total 126 25 @ 0x42f62f 0x40502b 0x405001 0x404de5 0xe7435b 0x45cc41 0xe7435a github.com/improbable-eng/thanos/pkg/store.startStreamSeriesSet.func1+0x18a /go/src/github.com/improbable-eng/thanos/pkg/store/proxy.go:318 ``` --- pkg/store/proxy.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/store/proxy.go b/pkg/store/proxy.go index bbcf8fdfa1..b9fd49edf0 100644 --- a/pkg/store/proxy.go +++ b/pkg/store/proxy.go @@ -294,10 +294,6 @@ func startStreamSeriesSet( return } - if ctx.Err() != nil { - return - } - if err != nil { wrapErr := errors.Wrapf(err, "receive series from %s", s.name) if partialResponse { @@ -315,7 +311,14 @@ func startStreamSeriesSet( s.warnCh.send(storepb.NewWarnSeriesResponse(errors.New(w))) continue } - s.recvCh <- r.GetSeries() + + select { + case s.recvCh <- r.GetSeries(): + continue + case <-ctx.Done(): + return + } + } }() return s