XdsClient: drop refs to ChannelState objects upon XdsClient shutdown (#30266)

* XdsClient: drop refs to ChannelState objects upon XdsClient shutdown

* be defensive to make sure we don't access a null pointer
pull/30325/head
Mark D. Roth 2 years ago committed by GitHub
parent 6fc2511e4d
commit a97596adbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      src/core/ext/xds/xds_client.cc

@ -1193,9 +1193,11 @@ void XdsClient::ChannelState::LrsCallState::Reporter::OnReportDoneLocked() {
// If there are no more registered stats to report, cancel the call.
auto it =
xds_client()->xds_load_report_server_map_.find(parent_->chand()->server_);
if (it == xds_client()->xds_load_report_server_map_.end() ||
it->second.load_report_map.empty()) {
it->second.channel_state->StopLrsCallLocked();
if (it == xds_client()->xds_load_report_server_map_.end()) return;
if (it->second.load_report_map.empty()) {
if (it->second.channel_state != nullptr) {
it->second.channel_state->StopLrsCallLocked();
}
return;
}
// Otherwise, schedule the next load report.
@ -1414,6 +1416,13 @@ void XdsClient::Orphan() {
// Clear cache and any remaining watchers that may not have been cancelled.
authority_state_map_.clear();
invalid_watchers_.clear();
// We may still be sending lingering queued load report data, so don't
// just clear the load reporting map, but we do want to clear the refs
// we're holding to the ChannelState objects, to make sure that
// everything shuts down properly.
for (auto& p : xds_load_report_server_map_) {
p.second.channel_state.reset(DEBUG_LOCATION, "XdsClient::Orphan()");
}
}
RefCountedPtr<XdsClient::ChannelState> XdsClient::GetOrCreateChannelStateLocked(

Loading…
Cancel
Save