-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix live metrics race condition #45944
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
Conversation
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.
Pull Request Overview
This PR addresses a race condition in the live metrics telemetry collector by introducing a read–write lock around the core counter operations.
- Adds a
ReadWriteLock
to synchronizegetAndRestart
,peek
, and per-itemadd
logic. - Refactors helper methods to accept a
Counters
instance rather than fetching it internally. - Introduces early type and null checks to skip locking when no counters are available or for unsupported telemetry.
Comments suppressed due to low confidence (2)
sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollector.java:62
- [nitpick] The field name
lock
is very generic; consider renaming it to something likecountersLock
orrwCountersLock
to clarify its purpose.
private final ReadWriteLock lock = new ReentrantReadWriteLock();
sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/quickpulse/QuickPulseDataCollector.java:94
- This method still uses
synchronized
instead of the newReadWriteLock
, causing mixed locking strategies that could lead to deadlock. Consider switching it tolock.readLock().lock()/unlock()
or removing the synchronized keyword entirely.
synchronized QuickPulseStatus getQuickPulseStatus() {
No description provided.