Skip flaky test on Mono where stderr callbacks are unsupported#980
Merged
stephentoub merged 4 commits intomainfrom Nov 20, 2025
Merged
Skip flaky test on Mono where stderr callbacks are unsupported#980stephentoub merged 4 commits intomainfrom
stephentoub merged 4 commits intomainfrom
Conversation
Co-authored-by: stephentoub <[email protected]>
Copilot
AI
changed the title
[WIP] Fix flaky CreateAsync_ValidProcessInvalidServer_StdErrCallbackInvoked test
Fix race condition in stderr reading for stdio transport
Nov 18, 2025
stephentoub
reviewed
Nov 18, 2025
src/ModelContextProtocol.Core/Client/StdioClientSessionTransport.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: stephentoub <[email protected]>
stephentoub
approved these changes
Nov 19, 2025
Contributor
|
@copilot, this change does not address the issue, as evidenced by CI failing with the problem: Assert.InRange() Failure: Value not in range
Range: (1 - 2147483647)
Actual: 0
at ModelContextProtocol.Tests.Transport.StdioClientTransportTests.CreateAsync_ValidProcessInvalidServer_StdErrCallbackInvoked () [0x001c8] in <69cc817959bb4cc3885cc3ba22a5c8d7>:0
Standard output
| [2025-11-19T13:20:43] ModelContextProtocol.Client.StdioClientTransport Information: stdio-sh connecting.
| [2025-11-19T13:20:43] ModelContextProtocol.Client.StdioClientTransport Information: stdio-sh starting server process. Command: 'sh'.
| [2025-11-19T13:20:43] ModelContextProtocol.Client.StdioClientTransport Information: stdio-sh started server process with PID 8519.
| [2025-11-19T13:20:43] ModelContextProtocol.Client.StdioClientSessionTransport Information: stdio-sh transport reading messages.
| [2025-11-19T13:20:43] ModelContextProtocol.Client.StdioClientSessionTransport Information: stdio-sh transport completed reading messages.
| [2025-11-19T13:20:43] ModelContextProtocol.Client.StdioClientSessionTransport Information: stdio-sh shutting down.
| [2025-11-19T13:20:43] ModelContextProtocol.Client.StdioClientSessionTransport Information: stdio-sh shut down.
| [2025-11-19T13:20:43] ModelContextProtocol.Client.McpClient Error: Client (ModelContextProtocol.Tests 1.0.0.0) client initialization error.
System.IO.IOException: The server shut down unexpectedly.
at System.Threading.Tasks.TaskExtensions.WaitAsync (System.Threading.Tasks.Task task, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) [0x00265] in <1fc557a7312b4427a8acfe69c788c8e6>:0
at System.Threading.Tasks.TaskExtensions.WaitAsync[T] (System.Threading.Tasks.Task`1[TResult] task, System.TimeSpan timeout, System.Threading.CancellationToken cancellationToken) [0x0007f] in <1fc557a7312b4427a8acfe69c788c8e6>:0
at ModelContextProtocol.McpSessionHandler.SendRequestAsync (ModelContextProtocol.Protocol.JsonRpcRequest request, System.Threading.CancellationToken cancellationToken) [0x0038c] in <1fc557a7312b4427a8acfe69c788c8e6>:0
at ModelContextProtocol.McpSession.SendRequestAsync[TParameters,TResult] (System.String method, TParameters parameters, System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[T] parametersTypeInfo, System.Text.Json.Serialization.Metadata.JsonTypeInfo`1[T] resultTypeInfo, ModelContextProtocol.Protocol.RequestId requestId, System.Threading.CancellationToken cancellationToken) [0x000f5] in <1fc557a7312b4427a8acfe69c788c8e6>:0
at ModelContextProtocol.Client.McpClientImpl.ConnectAsync (System.Threading.CancellationToken cancellationToken) [0x001e1] in <1fc557a7312b4427a8acfe69c788c8e6>:0 |
Co-authored-by: stephentoub <[email protected]>
Contributor
Author
... You're correct - my previous fix didn't address the issue. In 688a602, I've reverted those changes and implemented the proper fix: skipping the test on Mono where |
Copilot
AI
changed the title
Fix race condition in stderr reading for stdio transport
Skip flaky test on Mono where stderr callbacks are unsupported
Nov 19, 2025
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.
Fix flaky test: CreateAsync_ValidProcessInvalidServer_StdErrCallbackInvoked
Summary
Fixed the flaky test by properly skipping it on Mono runtime where
Process.ErrorDataReceivedcallbacks are not reliably supported.Root Cause
The test
CreateAsync_ValidProcessInvalidServer_StdErrCallbackInvokedrelies onProcess.ErrorDataReceivedevent to capture stderr output from a subprocess. This event is not reliably fired on Mono runtime, which is a known platform limitation.The test already had platform detection logic (
IsStdErrCallbackSupported => !PlatformDetection.IsMonoRuntime) to identify this incompatibility, but the skip attribute was commented out, allowing the test to run (and fail) on Mono.The test failed on Mono because:
ErrorDataReceivedevent callback is never invoked on Monocount >= 1)countstill at 0Solution
Uncommented the
[Fact(Skip = ..., SkipUnless = nameof(IsStdErrCallbackSupported))]attribute to properly skip the test on Mono platforms where it cannot succeed.Previous attempts to fix this by modifying
StdioClientSessionTransport.cswith additionalWaitForExit()calls were incorrect and have been reverted, as they did not address the root cause (Mono not firing the event at all).Changes
tests/ModelContextProtocol.Tests/Transport/StdioClientTransportTests.cs: Uncommented the skip attribute to skip test on Monosrc/ModelContextProtocol.Core/Client/StdioClientSessionTransport.cs: Reverted to original code (no changes)Testing & Verification
Security Summary
No security vulnerabilities were introduced or discovered. No code changes to production code.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.