Skip to content

Commit 37809ca

Browse files
Copilotstephentoub
andcommitted
Simplify ObserveSendFaults: remove #if NET block, inline ContinueWith at call site
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 69ed9fb commit 37809ca

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

src/ModelContextProtocol.Core/McpSessionHandler.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -553,30 +553,16 @@ public async Task<JsonRpcResponse> SendRequestAsync(JsonRpcRequest request, Canc
553553
// The response arrived via a concurrent channel before the transport send completed.
554554
// Cancel the still-running send and log any exception at debug level.
555555
sendCts.Cancel();
556-
_ = ObserveSendFaults(this, sendTask);
557-
558-
#if NET
559-
static async Task ObserveSendFaults(McpSessionHandler self, Task task)
560-
{
561-
await task.ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
562-
if (task.IsFaulted)
556+
_ = sendTask.ContinueWith(
557+
static (t, s) =>
563558
{
564-
self.LogTransportSendFaulted(self.EndpointName, task.Exception);
565-
}
566-
}
567-
#else
568-
static Task ObserveSendFaults(McpSessionHandler self, Task task) =>
569-
task.ContinueWith(
570-
static (t, s) =>
571-
{
572-
var handler = (McpSessionHandler)s!;
573-
handler.LogTransportSendFaulted(handler.EndpointName, t.Exception!);
574-
},
575-
self,
576-
CancellationToken.None,
577-
TaskContinuationOptions.OnlyOnFaulted,
578-
TaskScheduler.Default);
579-
#endif
559+
var handler = (McpSessionHandler)s!;
560+
handler.LogTransportSendFaulted(handler.EndpointName, t.Exception!);
561+
},
562+
this,
563+
CancellationToken.None,
564+
TaskContinuationOptions.OnlyOnFaulted,
565+
TaskScheduler.Default);
580566
}
581567
}
582568

0 commit comments

Comments
 (0)