Repository navigation
[rel/18.0] Fix concurrent modification in MetricsCollection - #16742
Merged
Azat Mukhametshin (azat-msft) merged 3 commits intoNov 20, 2026
Conversation
* fix: use ConcurrentDictionary in MetricsCollection to prevent concurrent modification MetricsCollection.Add is called from multiple threads during parallel test execution with data collectors. Using Dictionary causes InvalidOperationException when concurrent updates corrupt the state. Added regression test that exercises concurrent Add from 10 threads. Closes microsoft#15579 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix Moq verification: use IDictionary instead of Dictionary ConcurrentDictionary is not a subclass of Dictionary, so Moq's It.Is<Dictionary<...>> type check fails. Use IDictionary<...> which matches both Dictionary and ConcurrentDictionary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit bca4a11)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Azat Mukhametshin (azat-msft)
enabled auto-merge (squash)
November 20, 2026 00:32
Jan Krivanek (JanKrivanek)
approved these changes
Nov 20, 2026
Azat Mukhametshin (azat-msft)
merged commit Nov 20, 2026
efa9756
into
microsoft:rel/18.0
6 checks passed
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.
Description
Backport of #15581 to rel/18.0.
MetricsCollectionused a plainDictionary, and parallel attachment processing adds metrics from several threads. That failsTestRunWithCodeCoverageParallelintermittently withOperations that change non-concurrent collections must have exclusive access. It failed this way in 3 of the last 6 official rel/18.0 builds. rel/18.7 and later already have the fix.The backported regression test now asserts the exact count, because this branch's MSTest has no
Assert.IsGreaterThan.Related issue
Fixes #15579 on rel/18.0.