Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: fix race between Respond() and query/queryRange #5583

Merged
merged 2 commits into from Aug 10, 2022

Conversation

GiedriusS
Copy link
Member

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

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 thanos-io#5501.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
@GiedriusS GiedriusS merged commit d00a713 into thanos-io:main Aug 10, 2022
@GiedriusS GiedriusS deleted the fix_data_race_api branch August 10, 2022 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

query: with grafana gives inconsistent dashboard with every refresh
2 participants