Fix Segmentation fault on ingester due race condition when reading blocks that are being deleted #5119
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.
What this PR does:
When streaming metadata from ingesters we are closing the querier before the request finish.
This cause a race condition when the blocks from where the metadata is being read is deleted (when we close the querier we decrement the pendingRead waitgroup on the blocks allowing it to be deleted)
See:
cortex/pkg/ingester/ingester.go
Lines 1333 to 1334 in a63bbb0
cortex/pkg/ingester/ingester.go
Lines 1317 to 1321 in a63bbb0
This information is being read from an mmaped file on the index header, see:
https://github.com/prometheus/prometheus/blob/c70d85baed260f6013afd18d6cd0ffcac4339861/tsdb/index/index.go#L1517
This PR create commons methods that also return a cleanup function that the called should call after the request is done.
Which issue(s) this PR fixes:
Fixes #
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]