From 535de53dccd91393a0c076c4ae4970fbe1c8a018 Mon Sep 17 00:00:00 2001 From: Henry Yang Date: Thu, 22 Aug 2019 15:45:12 -0700 Subject: [PATCH] Fix onHostHealthUpdate got called before the cluster is resolved. Signed-off-by: Henry Yang --- source/extensions/clusters/redis/redis_cluster_lb.cc | 5 +++++ test/extensions/clusters/redis/redis_cluster_lb_test.cc | 1 + 2 files changed, 6 insertions(+) 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,