[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 7eaf22ecd5
PiperOrigin-RevId: 677889828
pull/37790/head
Mark D. Roth 2 months ago committed by Copybara-Service
parent a1b83dc995
commit 509db2463a
  1. 8
      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);
}

Loading…
Cancel
Save