diff --git a/source/extensions/clusters/redis/redis_cluster_lb.cc b/source/extensions/clusters/redis/redis_cluster_lb.cc index fefd17fff2fc..b4f3b1d06a2c 100644 --- a/source/extensions/clusters/redis/redis_cluster_lb.cc +++ b/source/extensions/clusters/redis/redis_cluster_lb.cc @@ -75,6 +75,11 @@ void RedisClusterLoadBalancerFactory::onHostHealthUpdate() { current_shard_vector = shard_vector_; } + // This can get called by cluster initialization before the Redis Cluster topology is resolved. + if (!current_shard_vector) { + return; + } + auto shard_vector = std::make_shared>(); for (auto const& shard : *current_shard_vector) { diff --git a/test/extensions/clusters/redis/redis_cluster_lb_test.cc b/test/extensions/clusters/redis/redis_cluster_lb_test.cc index dedcf8e51ec8..5e0ae78de9b2 100644 --- a/test/extensions/clusters/redis/redis_cluster_lb_test.cc +++ b/test/extensions/clusters/redis/redis_cluster_lb_test.cc @@ -44,6 +44,7 @@ class RedisClusterLoadBalancerTest : public testing::Test { factory_ = std::make_shared(random_); lb_ = std::make_unique(factory_); lb_->initialize(); + factory_->onHostHealthUpdate(); } void validateAssignment(Upstream::HostVector& hosts,