* Follow-up from #24965

* Avoid deadlock on XdsClient destruction
pull/25687/head
Yash Tibrewal 4 years ago committed by GitHub
parent 7021b72d1f
commit 5b9471da07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/core/ext/xds/xds_client.cc
  2. 6
      src/core/ext/xds/xds_client.h
  3. 4
      src/core/ext/xds/xds_server_config_fetcher.cc

@ -2213,13 +2213,17 @@ void XdsClientGlobalShutdown() {
} }
RefCountedPtr<XdsClient> XdsClient::GetOrCreate(grpc_error** error) { RefCountedPtr<XdsClient> XdsClient::GetOrCreate(grpc_error** error) {
MutexLock lock(g_mu); RefCountedPtr<XdsClient> xds_client;
if (g_xds_client != nullptr) { {
auto xds_client = g_xds_client->RefIfNonZero(); MutexLock lock(g_mu);
if (xds_client != nullptr) return xds_client; if (g_xds_client != nullptr) {
auto xds_client = g_xds_client->RefIfNonZero();
if (xds_client != nullptr) return xds_client;
}
xds_client = MakeRefCounted<XdsClient>(error);
if (*error != GRPC_ERROR_NONE) return nullptr;
g_xds_client = xds_client.get();
} }
auto xds_client = MakeRefCounted<XdsClient>(error);
g_xds_client = xds_client.get();
return xds_client; return xds_client;
} }

@ -88,7 +88,11 @@ class XdsClient : public DualRefCounted<XdsClient> {
explicit XdsClient(grpc_error** error); explicit XdsClient(grpc_error** error);
~XdsClient() override; ~XdsClient() override;
const XdsBootstrap* bootstrap() const { return bootstrap_.get(); } const XdsBootstrap& bootstrap() const {
// bootstrap_ is guaranteed to be non-null since XdsClient::GetOrCreate()
// would return a null object if bootstrap_ was null.
return *bootstrap_;
}
CertificateProviderStore& certificate_provider_store() { CertificateProviderStore& certificate_provider_store() {
return *certificate_provider_store_; return *certificate_provider_store_;

@ -51,7 +51,7 @@ class XdsServerConfigFetcher : public grpc_server_config_fetcher {
listening_address); listening_address);
auto* listener_watcher_ptr = listener_watcher.get(); auto* listener_watcher_ptr = listener_watcher.get();
listening_address = absl::StrReplaceAll( listening_address = absl::StrReplaceAll(
xds_client_->bootstrap()->server_listener_resource_name_template(), xds_client_->bootstrap().server_listener_resource_name_template(),
{{"%s", listening_address}}); {{"%s", listening_address}});
xds_client_->WatchListenerData(listening_address, xds_client_->WatchListenerData(listening_address,
std::move(listener_watcher)); std::move(listener_watcher));
@ -328,7 +328,7 @@ grpc_server_config_fetcher* grpc_server_config_fetcher_xds_create(
return nullptr; return nullptr;
} }
if (xds_client->bootstrap() if (xds_client->bootstrap()
->server_listener_resource_name_template() .server_listener_resource_name_template()
.empty()) { .empty()) {
gpr_log(GPR_ERROR, gpr_log(GPR_ERROR,
"server_listener_resource_name_template not provided in bootstrap " "server_listener_resource_name_template not provided in bootstrap "

Loading…
Cancel
Save