Skip to content

.NET: Fix loopback MCP test server shutdown race - #10252

Draft
SergeyMenshykh wants to merge 1 commit into
microsoft:mainfrom
SergeyMenshykh:sergeymenshykh-fix-flaky-foundry-a2a-scaffold-test
Draft

SergeyMenshykh wants to merge 1 commit into
microsoft:mainfrom
SergeyMenshykh:sergeymenshykh-fix-flaky-foundry-a2a-scaffold-test

Conversation

@SergeyMenshykh

Copy link
Copy Markdown
Collaborator

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, throwing InvalidOperationException: Not listening.

Description

  • Handle InvalidOperationException only around AcceptTcpClientAsync() and only when shutdown is requested.
  • Keep unrelated request-processing failures visible instead of suppressing them during shutdown.
  • Add a deterministic regression test that verifies request-processing errors still propagate during shutdown.

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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 10, 2026 19:34
@SergeyMenshykh
SergeyMenshykh deployed to github-app-auth November 10, 2026 19:34 — with GitHub Actions Active
@SergeyMenshykh
SergeyMenshykh deployed to github-app-auth November 10, 2026 19:34 — with GitHub Actions Active
@agent-framework-automation agent-framework-automation Bot added the .NET Usage: [Issues, PRs], Target: .Net label Nov 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 InvalidOperationException from AcceptTcpClientAsync() 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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch was successfully deployed

1 active deployment
github-app-auth — 37f16d05 Deployed Nov 10, 2026 by SergeyMenshykh via team_check #9232
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants