From 03046fd6884ecba9caf2b4004e12f4fdea8666a3 Mon Sep 17 00:00:00 2001 From: Frederic Desgreniers Date: Fri, 2 Oct 2020 15:17:24 -0400 Subject: [PATCH] Use up server count to decide what server to select. Or else this causes an index out of bounds error if upList.size() < allList.size() --- .../src/main/java/com/netflix/loadbalancer/RandomRule.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/RandomRule.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/RandomRule.java index 02604b69..5b9261fb 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/RandomRule.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/RandomRule.java @@ -48,6 +48,7 @@ public Server choose(ILoadBalancer lb, Object key) { List upList = lb.getReachableServers(); List allList = lb.getAllServers(); + int upCount = upList.size(); int serverCount = allList.size(); if (serverCount == 0) { /* @@ -57,7 +58,7 @@ public Server choose(ILoadBalancer lb, Object key) { return null; } - int index = chooseRandomInt(serverCount); + int index = chooseRandomInt(upCount); server = upList.get(index); if (server == null) {