bugfix: data race in head.Appender.AppendHistogram and Commit#15142
Merged
krajorama merged 2 commits intoprometheus:mainfrom Oct 14, 2024
Merged
bugfix: data race in head.Appender.AppendHistogram and Commit#15142krajorama merged 2 commits intoprometheus:mainfrom
krajorama merged 2 commits intoprometheus:mainfrom
Conversation
38df6b6 to
6c66c34
Compare
Two Appenders race when creating a series with a native histogram as the memSeries will be common and the lastHistogram field is written without lock. Signed-off-by: György Krajcsovits <[email protected]>
c3437c8 to
d2fa80c
Compare
Move writing memSeries lastHistogramValue and lastFloatHistogramValue after series creation under lock. The resulting code isn't totally correct in the sense that we're setting these values before Commit() , so they might be overwritten/rolled back later. Also Append of stale sample checks the values without lock, so there's still a potential race. The correct solution would be to set these only in Commit() which we actually do, but then Commit() would also need to process samples in order and not floats first, then histograms, then float histograms - which leads to not knowing what stale marker to write for histograms. Signed-off-by: György Krajcsovits <[email protected]>
d2fa80c to
bb70370
Compare
beorn7
approved these changes
Oct 10, 2024
Member
beorn7
left a comment
There was a problem hiding this comment.
Thanks for making things less bad… Looking forward to the Commit reorganization. (I have only vague memory why we did the floats first thing. It was probably much easier that way, and we didn't think about staleness back then.)
|
Ok |
Benz1993com
approved these changes
Oct 11, 2024
Benz1993com
approved these changes
Oct 11, 2024
Benz1993com
approved these changes
Oct 11, 2024
Tusenka
approved these changes
Oct 11, 2024
jesusvazquez
approved these changes
Oct 11, 2024
Member
|
Leaving it open for you to merge 👍 |
fionaliao
approved these changes
Oct 11, 2024
Tusenka
approved these changes
Oct 13, 2024
This was referenced Oct 14, 2024
Member
Author
|
Created issue #15177 to track the refactor. |
julienduchesne
pushed a commit
to julienduchesne/prometheus
that referenced
this pull request
Dec 13, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #15139
Two Appenders race when creating a series with a native histogram as the memSeries will be common and the lastHistogram field is written without lock.
Fix by:
Move writing
memSerieslastHistogramValueandlastFloatHistogramValueafter series creation under lock.
The resulting code isn't totally correct in the sense that we're setting
these values before
Commit(), so they might be overwritten/rolled backlater.
Also
Append()of stale sample checks the values without lock, so there'sstill a potential race.
The correct solution would be to set these only in
Commit()which weactually do, but then
Commit()would also need to process samples inorder and not floats first, then histograms, then float histograms - which
leads to not knowing what stale marker to write for histograms.
Might be easier to do after : #15112