Skip to content

Handle MTP test-host controller pipe timeouts by @Evangelink in #11152 (backport to rel/4.4) - #11180

Merged
Amaury Levé (Evangelink) merged 7 commits into
microsoft:rel/4.4from
nohwnd-bot:backport/11152/to/rel/4.4
Sep 11, 2026
Merged

Amaury Levé (Evangelink) merged 7 commits into
microsoft:rel/4.4from
nohwnd-bot:backport/11152/to/rel/4.4

Conversation

@nohwnd-bot

Copy link
Copy Markdown
Contributor

Backport of #11152 to rel/4.4

/cc Amaury Levé (@Evangelink)

Related to microsoft#4774

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Unix systems can report a forced close of an idle pipe as a connection reset instead of EOF. The test was failing on Linux with .NET 9.0 because it didn't handle this exception. This change adds a try-catch block to handle the IOException with ConnectionReset SocketError, which is the expected behavior on Unix when a pipe is closed abruptly.

This fixes the failing test ServerDisposal_WhenClientConnectsWithoutSendingRequest_DoesNotHang in the Linux Release build.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Evangelink

Copy link
Copy Markdown
Member

Fix for Linux Release Build Failure

The failing test \ServerDisposal_WhenClientConnectsWithoutSendingRequest_DoesNotHang\ is failing on Linux with .NET 9.0 because it doesn't handle the \ConnectionReset\ exception that Unix systems throw when a pipe is forcefully closed.

Root Cause

On Unix systems (Linux), when a pipe is closed abruptly, the system reports it as a "connection reset" error (\System.IO.IOException\ with inner \System.Net.Sockets.SocketException\ with \SocketErrorCode = ConnectionReset) instead of returning EOF (0 bytes).

Solution

The test needs to be updated to handle this expected Unix behavior. Update the \ServerDisposal_WhenClientConnectsWithoutSendingRequest_DoesNotHang\ method in \ est/UnitTests/Microsoft.Testing.Platform.UnitTests/Hosts/TestHostControllerCancellationTests.cs\ to wrap the read operation in a try-catch block:

\\csharp
byte[] responseBuffer = new byte[1];
try
{
Task readTask = client.ReadAsync(responseBuffer, 0, responseBuffer.Length, TestContext.CancellationToken);
Task completedTask = await Task.WhenAny(readTask, Task.Delay(DisposalTestTimeout, TestContext.CancellationToken));
Assert.AreSame(readTask, completedTask, "The client remained connected after server disposal.");
int bytesRead = await readTask;
Assert.AreEqual(0, bytesRead);
}
catch (IOException ex) when (ex.InnerException is System.Net.Sockets.SocketException
{
SocketErrorCode: System.Net.Sockets.SocketError.ConnectionReset,
})
{
// Unix can report a forced close of an idle pipe as a connection reset instead of EOF.
}
\\

This fix:

  1. Wraps the read operation in a try-catch block
  2. Also adds a timeout check using \Task.WhenAny\ to ensure the disposal completes without hanging
  3. Catches the \IOException\ with the \ConnectionReset\ socket error code, which is the expected behavior on Unix systems
  4. Allows the test to pass on both Windows (which returns 0 bytes) and Unix (which throws ConnectionReset)

Note: This fix has already been applied to the main branch and should be backported to rel/4.4 to fix the pipeline errors on this PR.

@Evangelink

Copy link
Copy Markdown
Member

Correction: the fix has now been pushed directly to this PR's head branch. The redundant follow-up PR was closed. Targeted validation is in progress.

@Evangelink
Amaury Levé (Evangelink) merged commit 730520a into microsoft:rel/4.4 Sep 11, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants