Handle Trailers-Only OK responses in streaming calls without exception handling#2697
Handle Trailers-Only OK responses in streaming calls without exception handling#2697JamesNK merged 3 commits intogrpc:masterfrom
Conversation
Avoid expensive TaskCanceledException in streaming calls when the server returns grpc-status in response headers (Trailers-Only). Set HttpResponseTcs before cleanup so MoveNextCore can read the empty stream gracefully. Also handle null HttpResponseMessage.Content on .NET Framework and read grpc-status from response headers in GetResponseStatus as a fallback.
|
Why have lots of people immediately thumbs up this? Do you know if there are existing unit tests for this scenario? |
One piece that I'm not entirely sure of is the removal of the await from |
|
@JamesNK -- any thoughts on this? |
|
@michaelmccord I've made some changes and added tests. I think it is ready to merge. Can you take a look at my updates and double check they're ok. |
Seems okay to me. |
Summary
TaskCanceledExceptionin server streaming calls when the server returns a Trailers-Only response with OK status by settingHttpResponseTcswithTrySetResultbeforeCleanuprunsGetResponseStatusto readgrpc-statusfrom response headers when not found in trailers (Trailers-Only responses per gRPC spec)HttpResponseMessage.Contenton .NET Framework inHttpContentClientStreamReader.MoveNextCoreawait CallTaskfromGetResponseHeadersCoreAsyncto prevent deadlock whenResponseHeadersAsyncis awaited beforeMoveNexton streaming calls with status in headersFixes #2696
Test plan
AsyncServerStreamingCall_TrailersOnly_TrailersReturnedWithHeaderspasses on all TFMs (net8.0, net9.0, net10.0, net462)AsyncServerStreamingCall_NoMessagesSuccess_SuccussCommitLoggedpasses on all TFMs including net462Grpc.Net.Client.Testssuite passes with 0 failures across all TFMsGrpc.AspNetCore.Server.Tests