diff --git a/src/JsonRpc/ResponseRouter.cs b/src/JsonRpc/ResponseRouter.cs index d66afc528..dfff2c42e 100644 --- a/src/JsonRpc/ResponseRouter.cs +++ b/src/JsonRpc/ResponseRouter.cs @@ -101,10 +101,10 @@ public async Task Returning(CancellationToken cancellation var tcs = new TaskCompletionSource(); _router.Requests.TryAdd(nextId, ( _method, tcs )); - cancellationToken.ThrowIfCancellationRequested(); - try { + cancellationToken.ThrowIfCancellationRequested(); + _router.OutputHandler.Value.Send( new OutgoingRequest { @@ -117,6 +117,13 @@ public async Task Returning(CancellationToken cancellation () => { if (tcs.Task.IsCompleted) return; + + if (cancellationToken.IsCancellationRequested) + { + tcs.SetCanceled(); + return; + } + _router.CancelRequest(new CancelParams { Id = nextId }); } );