Repository navigation
.NET: Fix loopback MCP test server shutdown race - #10252
SergeyMenshykh wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the test-only shutdown-race fix.
No open issues 🎉
What changed in this PR
Fixes a shutdown race in the .NET loopback MCP test server without changing production code.
Changes:
- Handles
InvalidOperationExceptionfromAcceptTcpClientAsync()only when shutdown is requested. - Adds a deterministic regression test confirming that request-processing failures still propagate during shutdown.
| File | Description |
|---|---|
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.Mcp.UnitTests/DefaultMcpToolHandlerLifetimeTests.cs |
Adds targeted listener-shutdown handling and a regression test for error propagation. |
Review effort: Balanced
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): 37f16d057036
Model: gpt-5.6-sol
Overview
The PR narrowly handles the loopback test server's accept-after-shutdown race without changing production code. The cancellation filter and catch placement constrain suppression to AcceptTcpClientAsync(), while disposal continues awaiting the request task and the new synchronized regression test confirms request-processing failures propagate unchanged. No publishable Critical, High, or Medium issue was established.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
Motivation
Fix the intermittent .NET Framework failure in
Factory_LoopbackInvocations_ReuseHandlerAndDisposeSeparateSessionsBeforeReturningAsync. During cleanup, the local test server can attempt to accept another connection after its listener has stopped, throwingInvalidOperationException: Not listening.Description
InvalidOperationExceptiononly aroundAcceptTcpClientAsync()and only when shutdown is requested.No production code changes. The .NET Framework suite passed; .NET 10 validation was interrupted.
AI assistance: implementation, regression test, and PR description.
Related Issue
N/A - trivial change: correct shutdown handling in a test helper without changing production behavior.
Observed in the failing CI job for #10244. This PR fixes the test cleanup race, not the Foundry scaffolding feature.