Skip to content

Commit bd41d2b

Browse files
Copilotstephentoub
andcommitted
Tighten catch filter: only catch OCE when tcs.Task has already completed, preventing masking of transport errors like connection closure
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 47ed90d commit bd41d2b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/ModelContextProtocol.Core/McpSessionHandler.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,10 @@ public async Task<JsonRpcResponse> SendRequestAsync(JsonRpcRequest request, Canc
544544
{
545545
await sendTask.ConfigureAwait(false);
546546
}
547-
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
547+
catch (OperationCanceledException) when (tcs.Task.IsCompleted && !cancellationToken.IsCancellationRequested)
548548
{
549+
// The response arrived via a concurrent channel (e.g., background GET SSE stream),
550+
// which cancelled the transport send. Proceed to retrieve the already-completed response.
549551
}
550552
finally
551553
{

0 commit comments

Comments
 (0)