From 509db2463ae5a9e9b768aa57b08d97c0bf79b757 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 23 Sep 2024 12:08:54 -0700 Subject: [PATCH] [health checking] connected subchannel may be null on READY notification (#37781) b/360085586 Closes #37781 COPYBARA_INTEGRATE_REVIEW=https://github.com/grpc/grpc/pull/37781 from markdroth:health_check_crash_fix 7eaf22ecd5b70a75469dbcf80bdeb73463257231 PiperOrigin-RevId: 677889828 --- src/core/load_balancing/health_check_client.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/load_balancing/health_check_client.cc b/src/core/load_balancing/health_check_client.cc index 523c1bd342a..b2d3f1ac3a9 100644 --- a/src/core/load_balancing/health_check_client.cc +++ b/src/core/load_balancing/health_check_client.cc @@ -403,13 +403,17 @@ void HealthProducer::OnConnectivityStateChange(grpc_connectivity_state state, << ": subchannel state update: state=" << ConnectivityStateName(state) << " status=" << status; MutexLock lock(&mu_); - state_ = state; - status_ = status; if (state == GRPC_CHANNEL_READY) { connected_subchannel_ = subchannel_->connected_subchannel(); + // If the subchannel became disconnected again before we got this + // notification, then just ignore the READY notification. We should + // get another notification shortly indicating a different state. + if (connected_subchannel_ == nullptr) return; } else { connected_subchannel_.reset(); } + state_ = state; + status_ = status; for (const auto& p : health_checkers_) { p.second->OnConnectivityStateChangeLocked(state, status); }