Add missing grpc_core::ExecCtx in binder connector callback (#27890)

Sometimes the callback might be invoked from main (UI) thread so we need
it.
pull/27909/head
Ming-Chuan 3 years ago committed by GitHub
parent 8b2b35db9c
commit 6d28740573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      src/core/ext/transport/binder/client/binder_connector.cc

@ -65,6 +65,7 @@ class BinderConnector : public grpc_core::SubchannelConnector {
args_ = args;
GPR_ASSERT(notify_ == nullptr);
GPR_ASSERT(notify != nullptr);
notify_ = notify;
result_ = result;
@ -84,7 +85,15 @@ class BinderConnector : public grpc_core::SubchannelConnector {
result_->channel_args = grpc_channel_args_copy(args_.channel_args);
result_->transport = transport;
grpc_core::ExecCtx::Run(DEBUG_LOCATION, notify_, GRPC_ERROR_NONE);
GPR_ASSERT(notify_ != nullptr);
// ExecCtx is required here for running grpc_closure because this callback
// might be invoked from non-gRPC code
if (grpc_core::ExecCtx::Get() == nullptr) {
grpc_core::ExecCtx exec_ctx;
grpc_core::ExecCtx::Run(DEBUG_LOCATION, notify_, GRPC_ERROR_NONE);
} else {
grpc_core::ExecCtx::Run(DEBUG_LOCATION, notify_, GRPC_ERROR_NONE);
}
Unref(); // Was referenced in BinderConnector::Connect
}

Loading…
Cancel
Save