Skip to content

Commit

Permalink
redis: fix onHostHealthUpdate got called before the cluster is resolv…
Browse files Browse the repository at this point in the history
…ed. (#8018)

Signed-off-by: Henry Yang <hyang@lyft.com>
  • Loading branch information
HenryYYang authored and mattklein123 committed Aug 23, 2019
1 parent 7f97060 commit faad477
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions source/extensions/clusters/redis/redis_cluster_lb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<RedisShardSharedPtr>>();

for (auto const& shard : *current_shard_vector) {
Expand Down
1 change: 1 addition & 0 deletions test/extensions/clusters/redis/redis_cluster_lb_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class RedisClusterLoadBalancerTest : public testing::Test {
factory_ = std::make_shared<RedisClusterLoadBalancerFactory>(random_);
lb_ = std::make_unique<RedisClusterThreadAwareLoadBalancer>(factory_);
lb_->initialize();
factory_->onHostHealthUpdate();
}

void validateAssignment(Upstream::HostVector& hosts,
Expand Down

0 comments on commit faad477

Please sign in to comment.