From 3203e75ec5d1e9a703a655552afbc16df78884c5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 12 May 2023 12:55:18 -0700 Subject: [PATCH] fix cancellation --- src/core/lib/channel/connected_channel.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/core/lib/channel/connected_channel.cc b/src/core/lib/channel/connected_channel.cc index dc6d9e2b017..bd6188dcf5a 100644 --- a/src/core/lib/channel/connected_channel.cc +++ b/src/core/lib/channel/connected_channel.cc @@ -710,13 +710,16 @@ ArenaPromise MakeServerCallPromise( // Promise factory that accepts a ServerMetadataHandle, and sends it as the // trailing metadata for this call. - auto send_trailing_metadata = - [call_data, stream = stream->InternalRef()]( - ServerMetadataHandle server_trailing_metadata) { - return GetContext()->SendServerTrailingMetadata( - stream->batch_target(), std::move(server_trailing_metadata), + auto send_trailing_metadata = [call_data, stream = stream->InternalRef()]( + ServerMetadataHandle + server_trailing_metadata) { + bool is_cancellation = + server_trailing_metadata->get(GrpcCallWasCancelled()).value_or(false); + return GetContext()->SendServerTrailingMetadata( + stream->batch_target(), std::move(server_trailing_metadata), + is_cancellation || !std::exchange(call_data->sent_initial_metadata, true)); - }; + }; // Runs the receive message loop, either until all the messages // are received or the server call is complete.