[sdk-metrics] Fix race condition for MemoryPoint Reclaim#5546
Merged
CodeBlanch merged 5 commits intoopen-telemetry:mainfrom Apr 18, 2024
Merged
[sdk-metrics] Fix race condition for MemoryPoint Reclaim#5546CodeBlanch merged 5 commits intoopen-telemetry:mainfrom
CodeBlanch merged 5 commits intoopen-telemetry:mainfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5546 +/- ##
==========================================
+ Coverage 83.38% 85.58% +2.19%
==========================================
Files 297 289 -8
Lines 12531 12493 -38
==========================================
+ Hits 10449 10692 +243
+ Misses 2082 1801 -281
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Member
|
@Yun-Ting Would you mind spinning up an issue to make sure we have coyote test coverage over this delta metric point reclaim feature? |
CodeBlanch
reviewed
Apr 18, 2024
This was referenced Sep 8, 2025
This was referenced Oct 11, 2025
Closed
This was referenced Oct 29, 2025
This was referenced Nov 19, 2025
Closed
Closed
This was referenced Jan 16, 2026
Closed
This was referenced Jan 24, 2026
Closed
Closed
Open
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.
Changes
On the main branch:
An update thread does the following:
MetricPointarrayReferenceCountfor theMetricPointat that indexMetricPointis valid for useMetricPointStatustoCollectPendingReferenceCountfor theMetricPointThe collect thread does the following:
MetricPointStatusfor a givenMetricPointisNoCollectPending, then check if it can be marked invalidMetricPointinvalid (this happens by setting theReferenceCounttoint.MinValuewhen no one is using it)MetricPointWhere's the race condition?
Consider this sequence of steps where both the Update thread and the Collect thread are working on the same MetricPoint
MetricPointindexMetricPointsMetricPointStatusfor theMetricPointMetricPointStatusisNoCollectPendingReferenceCountto1MetricPointis valid for useMetricPointStatustoCollectPending(This is the update that we would miss)ReferenceCountto0ReferenceCounttoint.MinValueas it finds theReferenceCountto be0MetricPointand misses the update that happened at T7Fix
I'm introducing a double-checked locking type construct to recheck if the
MetricPointStatuswas changed toCollectPendingbefore the Collect thread could mark the MetricPoint invalid for use. When that happens, we would now callSnapshotfor thatMetricPointand mark it to be reclaimed in the next Collect cycle. Note that theMetricPointwould remain invalid for use until the next Collect cycle reclaims it.