Skip to content

Commit fd2d71e

Browse files
halter73Copilot
andcommitted
Fix StreamClientSessionTransport swallowing caller-triggered cancellation
When the caller's CancellationToken triggers an OperationCanceledException during a pipe write, re-throw it instead of wrapping it in IOException. This ensures callers get the expected OperationCanceledException when they cancel their own token. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 27badfe commit fd2d71e

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/ModelContextProtocol.Core/Client/StreamClientSessionTransport.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public override async Task SendMessageAsync(JsonRpcMessage message, Cancellation
8585
await _serverInputStream.WriteAsync(s_newlineBytes, cancellationToken).ConfigureAwait(false);
8686
await _serverInputStream.FlushAsync(cancellationToken).ConfigureAwait(false);
8787
}
88+
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
89+
{
90+
throw;
91+
}
8892
catch (Exception ex)
8993
{
9094
LogTransportSendFailed(Name, id, ex);

0 commit comments

Comments
 (0)