Skip to content
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

CosmosDiagnostics: Fixes a race condition causing InvalidOperationException #2516

Merged
merged 16 commits into from
Jun 3, 2021

Conversation

j82w
Copy link
Contributor

@j82w j82w commented Jun 2, 2021

Pull Request Template

Description

Introduced in 3.17.0 PR #2097

This is a regression caused by making the ClientSideRequestStatisticsTraceDatum private fields to public. Previously these lists were protected by locks and when they were made public the locks were removed. This PR is adding the locks back and adding tests to ensure that if a background thread does update it while the list is being enumerated that it will not throw a InvalidOperationCancelledException.

Having a lock in the IEnumerable adds the possibility of deadlocks if the enumerator is not properly disposed of. To avoid this possibility a shallow copy of the list is lazily created. Once it is generated it will reuse the same shallow copy until the list is modified again.

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [] This change requires a documentation update

Closing issues

To automatically close an issue: closes #IssueNumber

ealsur
ealsur previously approved these changes Jun 2, 2021
Copy link
Member

@ealsur ealsur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only left 2 questions.

neildsh
neildsh previously approved these changes Jun 2, 2021
Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The yiel under a lock is not thread-safe and needs to be changed.

@j82w j82w dismissed stale reviews from neildsh and ealsur via f0045cf June 3, 2021 01:14
Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jake - LGTM now - except for minor comments on simplifying the shallow copy implementation

ealsur
ealsur previously approved these changes Jun 3, 2021
neildsh
neildsh previously approved these changes Jun 3, 2021
Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now - Thanks Jake!

@j82w j82w merged commit 5254c1c into master Jun 3, 2021
@j82w j82w deleted the users/jawilley/iTrace/clientsideRaceCondition branch June 3, 2021 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants