Repository navigation
Harden coordinator timer cleanup and tests - #15375
Merged
Merged
Conversation
Timer.Dispose() prevents future scheduling but does not wait for callbacks that are already running. A heartbeat or auto-shutdown callback could therefore continue after CoordinatorServer cleanup and access disposed state or write through an xUnit ITestOutputHelper after the test ended. Add a DrainableTimer that separates stopping from draining. RunAsync stops future callbacks without blocking its shutdown path, while CoordinatorServer.Dispose waits for active callbacks before disposing shared server state.
Block the auto-shutdown callback in the test debug output and verify that CoordinatorServer.Dispose does not return until the callback completes. Allow TestCoordinatorDebugOutput to observe messages so timer lifecycle tests can coordinate with callbacks without changing production code.
Coordinator builds can finish before the separately launched server reaches its idle timeout. Test cleanup could then inspect or delete trace files while the coordinator was still writing them. Wait for the per-test server mutex to disappear before restoring test state, then refresh the cached debug path and remove the trace directory.
Encapsulate pipe connection, handshake, protocol readers and writers, and common client messages in TestCoordinatorClient. Refactor CoordinatorServer tests to describe requests and responses directly while preserving raw protocol validation and concurrent ordering.
Centralize server creation, cancellation, and shutdown in documented test helpers so each test can focus on its coordinator protocol scenario. Keep auto-shutdown and disposal tests in control of their special lifecycle, and suppress CA2007 because xUnit tests intentionally use normal awaits.
Complete each client handshake as part of its concurrent connection instead of waiting for every pipe to connect before sending any protocol data. This lets accepted server handlers progress while the accept loop creates the remaining pipe instances, avoiding Windows .NET Framework pipe timeouts. Keep the test quarantined while stability evidence is collected.
DustinCampbell
temporarily deployed
to
copilot-pat-pool
October 23, 2026 00:00 — with
GitHub Actions
Inactive
DustinCampbell
temporarily deployed
to
copilot-pat-pool
October 23, 2026 00:01 — with
GitHub Actions
Inactive
DustinCampbell
had a problem deploying
to
copilot-pat-pool
October 23, 2026 00:01 — with
GitHub Actions
Failure
DustinCampbell
temporarily deployed
to
copilot-pat-pool
October 23, 2026 00:04 — with
GitHub Actions
Inactive
DustinCampbell
temporarily deployed
to
copilot-pat-pool
October 23, 2026 00:04 — with
GitHub Actions
Inactive
DustinCampbell
had a problem deploying
to
copilot-pat-pool
October 23, 2026 00:05 — with
GitHub Actions
Failure
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Exception-path cleanup can leave client pipes open and cause server shutdown waits to hang indefinitely.
2 open issues
What changed in this PR
This PR hardens coordinator shutdown and test cleanup so timer callbacks and external coordinator processes do not outlive the resources they use.
Changes:
- Separates timer stopping from callback draining and adds an in-flight callback disposal test.
- Waits for external coordinators during integration-test cleanup and restores the cached debug path.
- Centralizes test client/server lifecycle handling and performs handshakes during concurrent connections while retaining Windows quarantine.
| File | Description |
|---|---|
src/MSBuild.Coordinator/CoordinatorServer.DrainableTimer.cs |
Adds two-phase timer stopping and draining. |
src/MSBuild.Coordinator/CoordinatorServer.cs |
Integrates drainable timers and cancellation checks. |
src/MSBuild.Coordinator.UnitTests/TestCoordinatorDebugOutput.cs |
Adds an observer for synchronizing callback tests. |
src/MSBuild.Coordinator.UnitTests/TestCoordinatorClient.cs |
Encapsulates pipe ownership, handshakes, and protocol operations. |
src/MSBuild.Coordinator.UnitTests/GlobalSuppressions.cs |
Suppresses ConfigureAwait guidance for xUnit tests. |
src/MSBuild.Coordinator.UnitTests/CoordinatorServer_Tests.cs |
Refactors lifecycle helpers and tests callback draining. |
src/MSBuild.Coordinator.UnitTests/CoordinatorIntegration_Tests.cs |
Waits for coordinator exit and restores debug-path state. |
Review effort: Balanced
This was referenced Oct 24, 2026
This branch had an error being deployed
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.


Related issue(s): #14193
Context
Timer.Dispose()prevents future scheduling but does not wait for callbacks that are already running.A coordinator heartbeat or auto-shutdown callback could therefore continue after server cleanup,
access disposed state, or write through an xUnit
ITestOutputHelperafter its valid lifetime.Coordinator integration tests also allowed separately launched coordinator processes to outlive test
cleanup, leaving trace files open while subsequent tests inspected build-failure logs.
ConcurrentClients_AllReceiveGrantsalso withheld every client handshake until all concurrent pipeconnections completed. On Windows .NET Framework, accepted server handlers could block waiting for
those handshakes while another connection timed out.
Changes Made
DrainableTimerthat stops future callbacks separately from draining callbacksalready in progress.
RunAsyncexits and drain them whenCoordinatorServeris disposed.trace files.
TestCoordinatorClientto encapsulate pipe connections, handshakes, protocol I/O, andcommon client operations.
continue while remaining pipe instances are created.
ConcurrentClients_AllReceiveGrantsquarantined while the fix gathers stability evidence.Testing
The MSBuild Coordinator tests were run and are passing on .NET Framework and .NET 11.
Dependencies and Follow-up
ConcurrentClients_AllReceiveGrantsremains associated with #14193 and retains itsWindows-scoped
[ActiveIssue]attribute. It can be unquarantined after the quarantine pipelinecollects sufficient post-merge stability evidence.