diff --git a/src/csharp/Grpc.Core/Internal/AsyncCall.cs b/src/csharp/Grpc.Core/Internal/AsyncCall.cs index 830a1f4edc6..899af94fb6c 100644 --- a/src/csharp/Grpc.Core/Internal/AsyncCall.cs +++ b/src/csharp/Grpc.Core/Internal/AsyncCall.cs @@ -626,6 +626,14 @@ namespace Grpc.Core.Internal if (status.StatusCode != StatusCode.OK) { streamingResponseCallFinishedTcs.SetException(new RpcException(status, receivedStatus.Trailers)); + if (status.StatusCode == StatusCode.Cancelled) + { + // Make sure the exception set to the Task is observed, + // otherwise this can trigger "Unobserved exception" when the response stream + // is not read until its end and the task created by the TCS is garbage collected. + // See https://github.com/grpc/grpc/issues/17458 + var _ = streamingResponseCallFinishedTcs.Task.Exception; + } return; }