Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
api: fix race between Respond() and query/queryRange (#5583)
* api: fix race between Respond() and query/queryRange Fix a data race between Respond() and query/queryRange functions by returning an extra optional function from instrumented functions that releases the resources i.e. calls Close(). Cannot reproduce the following race: ``` ================== WARNING: DATA RACE Write at 0x00c00566fa00 by goroutine 562: github.com/prometheus/prometheus/promql.(*evaluator).eval() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:1450 +0x8044 github.com/prometheus/prometheus/promql.(*evaluator).rangeEval() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:1060 +0x2684 github.com/prometheus/prometheus/promql.(*evaluator).eval() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:1281 +0x42a4 github.com/prometheus/prometheus/promql.(*evaluator).rangeEval() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:1060 +0x2684 github.com/prometheus/prometheus/promql.(*evaluator).eval() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:1281 +0x42a4 github.com/prometheus/prometheus/promql.(*evaluator).Eval() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:989 +0xf5 github.com/prometheus/prometheus/promql.(*Engine).execEvalStmt() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:645 +0xa77 github.com/prometheus/prometheus/promql.(*Engine).exec() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:595 +0x71e github.com/prometheus/prometheus/promql.(*query).Exec() /home/giedrius/go/pkg/mod/github.com/vinted/prometheus@v1.8.2-0.20220808145920-5c879a061105/promql/engine.go:197 +0x250 github.com/thanos-io/thanos/pkg/api/query.(*QueryAPI).query() /home/giedrius/dev/thanos/pkg/api/query/v1.go:387 +0xbf2 github.com/thanos-io/thanos/pkg/api/query.(*QueryAPI).query-fm() ... Previous read at 0x00c00566fa00 by goroutine 570: github.com/prometheus/prometheus/promql.(*Point).MarshalJSON() <autogenerated>:1 +0x4e encoding/json.addrMarshalerEncoder() /usr/lib/go-1.19/src/encoding/json/encode.go:495 +0x1af encoding/json.condAddrEncoder.encode() /usr/lib/go-1.19/src/encoding/json/encode.go:959 +0x94 encoding/json.condAddrEncoder.encode-fm() <autogenerated>:1 +0xa4 encoding/json.arrayEncoder.encode() /usr/lib/go-1.19/src/encoding/json/encode.go:915 +0x10e encoding/json.arrayEncoder.encode-fm() <autogenerated>:1 +0x90 encoding/json.sliceEncoder.encode() ``` Should fix #5501. Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> * CHANGELOG: add item Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com> Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
- Loading branch information