Skip to content

Commit a698b02

Browse files
committed
Fix test regression
1 parent 0647e71 commit a698b02

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/ModelContextProtocol.Core/Client/StdioClientSessionTransport.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ public override async Task SendMessageAsync(JsonRpcMessage message, Cancellation
4848
protected override async ValueTask CleanupAsync(Exception? error = null, CancellationToken cancellationToken = default)
4949
{
5050
// Only run the full stdio cleanup once (handler detach, process kill, etc.).
51-
// But always ensure the channel is completed so DisposeAsync's
52-
// "await Completion" doesn't hang when the ReadMessagesAsync path
53-
// is still mid-cleanup (e.g. blocked in WaitForExitAsync).
51+
// But always call base.CleanupAsync — it cancels the shutdown CTS (which
52+
// unblocks the primary path if it's stuck in WaitForExitAsync), waits for
53+
// the read task to complete (so the primary path can call SetDisconnected
54+
// with full StdioClientCompletionDetails), and calls SetDisconnected itself
55+
// as a fallback. We wrap the error in TransportClosedException so the
56+
// fallback SetDisconnected still produces StdioClientCompletionDetails
57+
// rather than a bare ClientCompletionDetails.
5458
if (Interlocked.Exchange(ref _cleanedUp, 1) != 0)
5559
{
56-
SetDisconnected(error);
60+
await base.CleanupAsync(new TransportClosedException(BuildCompletionDetails(error)), cancellationToken).ConfigureAwait(false);
5761
return;
5862
}
5963

0 commit comments

Comments
 (0)