-
Notifications
You must be signed in to change notification settings - Fork 287
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
fix Metric livelock by replacing potential infinate loop in MetricValuesBuffer.GetAndResetValue #2612
Merged
Conversation
This file contains 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
cijothomas
reviewed
Jun 16, 2022
BASE/src/Microsoft.ApplicationInsights/Metrics/Extensibility/MetricValuesBuffer.cs
Outdated
Show resolved
Hide resolved
cijothomas
reviewed
Jun 16, 2022
BASE/src/Microsoft.ApplicationInsights/Metrics/Extensibility/MetricValuesBuffer.cs
Outdated
Show resolved
Hide resolved
TimothyMothra
changed the title
fix Metric deadlock by replacing potential infinate loop in MetricValuesBuffer.GetAndResetValue
fix Metric livelock by replacing potential infinate loop in MetricValuesBuffer.GetAndResetValue
Jun 16, 2022
cijothomas
reviewed
Jun 17, 2022
cijothomas
reviewed
Jun 17, 2022
BASE/src/Microsoft.ApplicationInsights/Metrics/Extensibility/MetricValuesBuffer.cs
Outdated
Show resolved
Hide resolved
cijothomas
approved these changes
Jun 17, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Need some validation before stable releasing this.
rajkumar-rangaraj
approved these changes
Jun 17, 2022
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.
Fix Issue #1186.
This PR mitigates the potential infinite while loop in
MetricValuesBuffer
by adding an exit condition.Changes
MetricValuesBuffer.GetAndResetValue()
.Explanation
MetricValuesBuffer
has a section that could get stuck in an infinate loop here:ApplicationInsights-dotnet/BASE/src/Microsoft.ApplicationInsights/Metrics/Extensibility/MetricValuesBuffer.cs
Lines 90 to 103 in 9276687
GetAndResetValueOnce
will read a value from the buffer at an index and set reset that toDouble.NaN
.This loop has no way to breakout if another thread has already reset this value.
This would also affect the
lock
inMetricSeriesAggregatorBase
:ApplicationInsights-dotnet/BASE/src/Microsoft.ApplicationInsights/Metrics/Extensibility/MetricSeriesAggregatorBase.cs
Lines 398 to 411 in 5aed71e
Alternatives considered
My previous PR replaced the lock in MetricSeriesAggregatorBase. #2595.
However, when considering what happens when we break out...
Breaking out of
MetricSeriesAggregatorBase
may cause the SDK to lose a complete batch of metrics.Instead, we should only drop a single metric if breaking out of
MetricValuesBuffer
.Checklist
For significant contributions please make sure you have completed the following items:
The PR will trigger build, unit tests, and functional tests automatically. Please follow these instructions to build and test locally.
Notes for authors:
Notes for reviewers:
/AzurePipelines run
will queue all builds/AzurePipelines run <pipeline-name>
will queue a specific build