Fix mixed synchronization for _runStartedClients in ParallelProxyExecutionManager#16202
Open
azat-msft wants to merge 1 commit into
Open
Fix mixed synchronization for _runStartedClients in ParallelProxyExecutionManager#16202azat-msft wants to merge 1 commit into
azat-msft wants to merge 1 commit into
Conversation
…utionManager _runStartedClients was incremented via Interlocked.Increment from a Task.Run lambda outside any lock, while it is read inside lock (_executionStatusLockObject) in HandlePartialRunComplete. The lock did not fence the atomic write from the concurrent thread, which is formally a data race per the C# memory model. Increment the field under _executionStatusLockObject instead, matching how _runCompletedClients is handled, so the write and read are guarded by the same lock. Addresses task 4 of microsoft#16195. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates ParallelProxyExecutionManager in CrossPlatEngine to eliminate mixed synchronization on the _runStartedClients counter, aligning its update strategy with the lock-based reads performed during run-completion handling (Task 4 of #16195).
Changes:
- Moves
_runStartedClientsincrement from anInterlocked.Incrementperformed outside a lock to alock (_executionStatusLockObject)-guarded increment. - Adds explanatory comments clarifying why the increment is now performed under the execution-status lock.
Comments suppressed due to low confidence (1)
src/Microsoft.TestPlatform.CrossPlatEngine/Client/Parallel/ParallelProxyExecutionManager.cs:419
- _runStartedClients is now incremented under _executionStatusLockObject, but the subsequent trace statements read _runStartedClients outside the lock. Since the motivation is to avoid mixed synchronization for this field, consider capturing a local snapshot under the lock (and use that for the trace lines) so all reads/writes in this block share the same synchronization pattern and the comment remains accurate.
EqtTrace.Verbose("ParallelProxyExecutionManager.StartTestRunOnConcurrentManager: Initializing test run. Started clients: " + _runStartedClients);
proxyExecutionManager.InitializeTestRun(testRunCriteria, eventHandler);
EqtTrace.Verbose("ParallelProxyExecutionManager.StartTestRunOnConcurrentManager: Execution starting. Started clients: " + _runStartedClients);
proxyExecutionManager.StartTestRun(testRunCriteria, eventHandler);
Member
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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.
Addresses task 4 of #16195.
Problem
_runStartedClients in
ParallelProxyExecutionManagerwas incremented viaInterlocked.Incrementfrom aTask.Runlambda outside any lock, but read insidelock (_executionStatusLockObject)inHandlePartialRunComplete. The lock does not fence the atomic write performed on a concurrent thread, so per the C# memory model this is formally a data race (an existing// BUGcomment acknowledged the concern).Fix
Increment
_runStartedClientsunder_executionStatusLockObject, matching how the sibling counter_runCompletedClientsis already handled. This guards the write and read with the same lock.Validation
dotnet build src/Microsoft.TestPlatform.CrossPlatEngine -c Release— 0 warnings, 0 errors.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com