fix unobserved task exception problem for non-exhausted response streams

pull/21202/head
Jan Tattermusch 5 years ago
parent 87bb6ed2bf
commit d34f7f3df5
  1. 8
      src/csharp/Grpc.Core/Internal/AsyncCall.cs

@ -626,6 +626,14 @@ namespace Grpc.Core.Internal
if (status.StatusCode != StatusCode.OK) if (status.StatusCode != StatusCode.OK)
{ {
streamingResponseCallFinishedTcs.SetException(new RpcException(status, receivedStatus.Trailers)); 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; return;
} }

Loading…
Cancel
Save