From 2575e8a24e62625c963e7f02c874ffa040a2f347 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Thu, 12 Dec 2019 12:45:11 -0800 Subject: [PATCH] Cancel the endpoint watch only when using XdsResolver --- .../ext/filters/client_channel/lb_policy/xds/xds.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index cb0cfcd6d66..bfe3a3c63c6 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -739,10 +739,14 @@ void XdsLb::ShutdownLocked() { } fallback_policy_.reset(); pending_fallback_policy_.reset(); - // Cancel the endpoint watch here instead of in our dtor, because the - // watcher holds a ref to us. - xds_client()->CancelEndpointDataWatch(StringView(eds_service_name()), - endpoint_watcher_); + // Cancel the endpoint watch here instead of in our dtor if we are using the + // XdsResolver, because the watcher holds a ref to us and we might not be + // destroying the Xds client leading to a situation where the Xds lb policy is + // never destroyed. + if (xds_client_from_channel_ != nullptr) { + xds_client()->CancelEndpointDataWatch(StringView(eds_service_name()), + endpoint_watcher_); + } if (config_->lrs_load_reporting_server_name() != nullptr) { xds_client()->RemoveClientStats( StringView(config_->lrs_load_reporting_server_name()),