From 837c4ce589924640bbc395128ba07cbeffdd5b5c Mon Sep 17 00:00:00 2001 From: jiangtaoli2016 Date: Wed, 24 Jun 2020 10:54:58 -0700 Subject: [PATCH] Fix ALTS shutdown crash on envoy --- .../alts/handshaker/alts_handshaker_client.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc index 61927276195..067f46c46d6 100644 --- a/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +++ b/src/core/tsi/alts/handshaker/alts_handshaker_client.cc @@ -661,11 +661,18 @@ static void handshaker_client_destruct(alts_handshaker_client* c) { // TODO(apolcyn): we could remove this indirection and call // grpc_call_unref inline if there was an internal variant of // grpc_call_unref that didn't need to flush an ExecCtx. - grpc_core::ExecCtx::Run( - DEBUG_LOCATION, - GRPC_CLOSURE_CREATE(handshaker_call_unref, client->call, - grpc_schedule_on_exec_ctx), - GRPC_ERROR_NONE); + if (grpc_core::ExecCtx::Get() == nullptr) { + // Unref handshaker call if there is no exec_ctx, e.g., in the case of + // Envoy ALTS transport socket. + grpc_call_unref(client->call); + } else { + // Using existing exec_ctx to unref handshaker call. + grpc_core::ExecCtx::Run( + DEBUG_LOCATION, + GRPC_CLOSURE_CREATE(handshaker_call_unref, client->call, + grpc_schedule_on_exec_ctx), + GRPC_ERROR_NONE); + } } }