testfx icon indicating copy to clipboard operation
testfx copied to clipboard

Potential MTP pipe bug

Open Evangelink opened this issue 11 months ago • 3 comments

Flakiness

Tests failed: .NET Testing Platform v1.5.1+0ed409d401 (UTC 01/13/2025) [linux-x64 - net8.0] [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
Telemetry [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
--------- [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
Microsoft Testing Platform collects usage data in order to help us improve your experience. The data is collected by Microsoft and are not shared with anyone. [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
You can opt-out of telemetry by setting the TESTINGPLATFORM_TELEMETRY_OPTOUT or DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
Read more about Microsoft Testing Platform telemetry: https://aka.ms/testingplatform/telemetry [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
Unhandled exception. System.OperationCanceledException: The operation was canceled. [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at System.Threading.CancellationToken.ThrowOperationCanceledException() [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at System.Threading.CancellationToken.ThrowIfCancellationRequested() [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource<System.Net.Sockets.Socket>.GetResult(Int16 token) [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at System.IO.Pipes.NamedPipeServerStream.<>c__DisplayClass25_0.<<WaitForConnectionAsync>g__WaitForConnectionAsyncCore|0>d.MoveNext() [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
--- End of stack trace from previous location --- [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at Microsoft.Testing.Platform.IPC.NamedPipeServer.WaitConnectionAsync(CancellationToken cancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/IPC/NamedPipeServer.cs:line 81 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at Microsoft.Testing.Platform.Hosts.TestHostControllersTestHost.InternalRunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControllersTestHost.cs:line 258 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at Microsoft.Testing.Platform.Hosts.TestHostControllersTestHost.InternalRunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/TestHostControllersTestHost.cs:line 333 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunTestAppAsync(CancellationToken testApplicationCancellationToken) in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 110 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 34 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at Microsoft.Testing.Platform.Hosts.CommonTestHost.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Hosts/CommonTestHost.cs:line 71 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at Microsoft.Testing.Platform.Builder.TestApplication.RunAsync() in /_/src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs:line 244 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at TestingPlatformEntryPoint.Main(String[] args) in /_/artifacts/obj/MyProject.Tests/release/TestPlatformEntryPoint.cs:line 16 [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj]
   at TestingPlatformEntryPoint.<Main>(String[] args) [/__w/1/s/tests/MyProject.Tests/MyProject.Tests.csproj] 

Evangelink avatar Jan 24 '25 08:01 Evangelink

@Evangelink Is this actionable?

Youssef1313 avatar Jun 03 '25 06:06 Youssef1313

This is for investigation, the main goal/principle is to say that we don't expect unhandled exception. It seems that we have a path where this should be handled.

Evangelink avatar Jun 13 '25 08:06 Evangelink

Looking at the stack trace. CommonTestHost.RunAsync already handles OperationCanceledException when testApplicationCancellationToken.IsCancellationRequested is true.

So, based on this stack trace, we got OperationCanceledException, but testApplicationCancellationToken.IsCancellationRequested wasn't true.

The WaitConnectionAsync call in question is:

                // Wait for the test host controller to connect
                using (CancellationTokenSource timeout = new(TimeSpan.FromSeconds(timeoutSeconds)))
                using (var linkedToken = CancellationTokenSource.CreateLinkedTokenSource(timeout.Token, abortRun))
                {
                    await _logger.LogDebugAsync("Wait connection from the test host process").ConfigureAwait(false);
                    await testHostControllerIpc.WaitConnectionAsync(linkedToken.Token).ConfigureAwait(false);
                }

That means, we got cancellation through the timeout, and not through our global cancellation token, but we only handle the latter.

Why a timeout happened in the first place is unknown.

Youssef1313 avatar Jun 13 '25 11:06 Youssef1313