Skip to content

Commit

Permalink
store: fix nil panic in proxy heap
Browse files Browse the repository at this point in the history
With lazy proxying we need to wait for at least one response before we
can build a heap properly.

Closes thanos-io#5717
Fixes thanos-io#5552.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
  • Loading branch information
GiedriusS authored and matej-g committed Sep 30, 2022
1 parent 8a46d17 commit f211613
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/store/proxy_heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ func (l *lazyRespSet) Empty() bool {
l.bufferedResponsesMtx.Lock()
defer l.bufferedResponsesMtx.Unlock()

// NOTE(GiedriusS): need to wait here for at least one
// response so that we could build the heap properly.
if l.noMoreData && len(l.bufferedResponses) == 0 {
return true
}

for len(l.bufferedResponses) == 0 {
l.dataOrFinishEvent.Wait()
if l.noMoreData && len(l.bufferedResponses) == 0 {
break
}
}

return len(l.bufferedResponses) == 0 && l.noMoreData
}

Expand Down
5 changes: 5 additions & 0 deletions test/e2e/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1561,4 +1561,9 @@ func TestConnectedQueriesWithLazyProxy(t *testing.T) {
return "sum(up)"
}, time.Now, promclient.QueryOptions{}, 1)
testutil.Equals(t, model.SampleValue(1.0), result[0].Value)

instantQuery(t, context.Background(), querier2.Endpoint("http"), func() string {
return "sum(metric_that_does_not_exist)"
}, time.Now, promclient.QueryOptions{}, 0)

}

0 comments on commit f211613

Please sign in to comment.