Repository navigation
Harden coordinator client lifecycle races - #14240
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Hardens MSBuild Coordinator client/server lifecycle and deferred-grant handling to reduce race conditions around heartbeats, disposal, and deferred waiters, building on prior coordinator refactoring.
Changes:
- Centralizes coordinator client transport ownership on
CoordinatorClient.Connectionand serializes client writes. - Adds a dedicated heartbeat timer that drains in-flight callbacks during disposal / deferred-wait periods.
- Improves server-side deferred-grant notification flow to handle disconnected waiters and queue additional grants.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/MSBuild.Coordinator/CoordinatorServer.cs | Refactors grant release + deferred notification draining to better handle disconnected waiters. |
| src/MSBuild.Coordinator/CoordinatorServer.ConnectedClient.cs | Makes connected-client disposal idempotent. |
| src/MSBuild.Coordinator.UnitTests/TestCoordinatorDebugOutput.cs | Routes interpolated debug output through the same WriteLine(string) path. |
| src/MSBuild.Coordinator.UnitTests/CoordinatorClient_Tests.cs | Adds regression tests for idempotent dispose and deferred-wait heartbeats; adjusts pipe server behavior. |
| src/Build/Microsoft.Build.csproj | Includes new CoordinatorClient.HeartbeatTimer.cs in the build. |
| src/Build/BackEnd/BuildManager/CoordinatorClient.TestAccessor.cs | Clarifies pipe-stream ownership transfer and ensures disposal in finally. |
| src/Build/BackEnd/BuildManager/CoordinatorClient.HeartbeatTimer.cs | Introduces a disposable heartbeat timer that waits for in-flight callbacks. |
| src/Build/BackEnd/BuildManager/CoordinatorClient.cs | Moves client heartbeats/writes to Connection and makes Dispose idempotent. |
| src/Build/BackEnd/BuildManager/CoordinatorClient.Connection.cs | Makes connection own pipe/reader/writer directly, serializes writes, and makes disposal idempotent. |
Keep coordinator client ownership on Connection, serialize client writes, and drain heartbeat timers before disposing the transport. Co-authored-by: Copilot App <[email protected]> Copilot-Session: db19afae-f9ef-45b0-b7c2-e0ced2e134d8
Avoid recursive deferred-grant release handling and make connected-client disposal idempotent while preserving existing server write ownership. Co-authored-by: Copilot App <[email protected]> Copilot-Session: db19afae-f9ef-45b0-b7c2-e0ced2e134d8
Cover idempotent client disposal and deferred-grant heartbeat behavior, and remove unused test debug output plumbing. Co-authored-by: Copilot App <[email protected]> Copilot-Session: db19afae-f9ef-45b0-b7c2-e0ced2e134d8
Address review feedback by disposing BinaryWriter instances in coordinator client tests while tolerating broken-pipe flush during disconnect verification. Co-authored-by: Copilot App <[email protected]> Copilot-Session: db19afae-f9ef-45b0-b7c2-e0ced2e134d8
emaf
force-pushed
the
emaf-coordinator-hardening-fixes
branch
from
July 18, 2026 03:26
901ed73 to
d1ea28c
Compare
DustinCampbell
approved these changes
Jul 21, 2026
Revert unnecessary changes to TestCoordinatorDebugOutput so the PR only carries coordinator lifecycle hardening changes. Co-authored-by: Copilot App <[email protected]> Copilot-Session: db19afae-f9ef-45b0-b7c2-e0ced2e134d8
AR-May
enabled auto-merge (squash)
July 22, 2026 15:01
DustinCampbell
approved these changes
Jul 22, 2026
This was referenced Jul 25, 2026
AlesProkop
added a commit
that referenced
this pull request
Jul 29, 2026
Automated flaky-test quarantine (2026-07-27). --- ## Quarantine: `SingleBuild_CoordinatorCapsMaxNodeCount` **Flaky-test key** (automated de-duplication — do not edit): ```text flaky-test-id: Microsoft.Build.Coordinator.UnitTests.CoordinatorIntegration_Tests.SingleBuild_CoordinatorCapsMaxNodeCount ``` Tracked by #14516 - **Action**: quarantine (6a) — added `[ActiveIssue("https://github.com/dotnet/msbuild/issues/14516")]` - **File**: `src/MSBuild.Coordinator.UnitTests/CoordinatorIntegration_Tests.cs` - **Distinct sources**: 3 (3 PRs: #13609, #14240, #14470; 0 rolling builds) - **Legs**: CoreOnLinux, CoreOnWindows, FullOnWindows Release - **TFMs**: net10.0, net11.0, net472 - **Error hashes**: 3 distinct (`4039adb7`, `55b6331b`, `ba217936`) - **First seen**: 2026-07-17 | **Last seen**: 2026-07-23 - [Sample build](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1523327) --- ## Also tracked this run (new issues filed; quarantine eligible next run) - `Microsoft.Build.BuildCheck.UnitTests.EndToEndTests.TFMinNonSdkCheckTest` (3 rolling builds, 4 error hashes) - `Microsoft.Build.Engine.UnitTests.MSBuildServer_Tests.ServerSpawnAndReuseAreLoggedToBuildLog` (3 rolling builds, 3 error hashes) - `Microsoft.Build.UnitTests.CommunicationUtilitiesTests.GetEnvVars` (3 rolling builds, 2 error hashes) --- ## Skipped (possible regression — human triage needed) The following tests showed a **single stable error hash** failing across the same set of 4 rolling builds with no PR sources, which may indicate a regression rather than a flake: - `Microsoft.Build.UnitTests.CodeTaskFactoryTests.*` (7 tests, hash `2f59b830`, builds 1506834/1514373/1517682/1527742) - `Microsoft.Build.UnitTests.CodeTaskFactoryTests.EmbedsGenerated*` (2 tests, hash `d888cdeb`, same builds) These were **not quarantined** to avoid masking a real bug. Human investigation recommended. > [!WARNING] > <details> > <summary>Firewall blocked 2 domains</summary> > > The following domains were blocked by the firewall during workflow execution: > > - `awmgmcpg` > - `southcentralus0.in.applicationinsights.azure.com` >> To allow these domains, add them to the `network.allowed` list in your workflow frontmatter: > > ```yaml > network: > allowed: > - defaults > - "awmgmcpg" > - "southcentralus0.in.applicationinsights.azure.com" > ``` > > See [Network Configuration](https://github.github.com/gh-aw/reference/network/) for more information. > > </details> > Generated by [Flaky Test Triage](https://github.com/dotnet/msbuild/actions/runs/30267259222) · sonnet46 · 153.8 AIC · ⌖ 6.72 AIC · ⊞ 14.7K · [◷](https://github.com/search?q=repo%3Adotnet%2Fmsbuild+%22gh-aw-workflow-id%3A+flaky-test-detector.agent%22&type=pullrequests) <!-- gh-aw-agentic-workflow: Flaky Test Triage, engine: copilot, version: 1.0.70, model: claude-sonnet-4.6, id: 30267259222, workflow_id: flaky-test-detector.agent, run: https://github.com/dotnet/msbuild/actions/runs/30267259222 --> <!-- gh-aw-workflow-id: flaky-test-detector.agent --> <!-- gh-aw-workflow-call-id: dotnet/msbuild/flaky-test-detector.agent --> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <[email protected]> Co-authored-by: Aleš Prokop <[email protected]>
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.
Context
This PR hardens coordinator client/server lifecycle handling on top of #14224.
Coordinator client writes can come from multiple lifecycle paths: regular heartbeat timers, deferred-wait heartbeat pumps, and
Disposereleasing a grant. Those paths need to avoid overlappingBinaryWriterwrites and timer callbacks racing with connection ownership changes or disposal.Changes Made
CoordinatorClient.Connection.Connection, so heartbeats, deferred-wait heartbeats, and release messages share one write path.Testing
.\build.cmd -v quietdotnet msbuild src\Build\Microsoft.Build.csproj -p:Configuration=Release -v:qdotnet msbuild src\MSBuild.Coordinator\MSBuild.Coordinator.csproj -p:Configuration=Release -v:qdotnet test src\MSBuild.Coordinator.UnitTests\MSBuild.Coordinator.UnitTests.csproj -c Release