From 179dadf33e2be9fdc8977e84f2b9d06dabb3cca3 Mon Sep 17 00:00:00 2001 From: Mathias Gebbe Date: Wed, 7 Feb 2018 13:28:59 +0100 Subject: [PATCH] Fix for RoundRobin in Zuul Proxy https://github.com/Netflix/ribbon/issues/361 We always got the same server as response --- .../com/netflix/loadbalancer/AbstractServerPredicate.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java index d347e058..77f54a4a 100644 --- a/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java +++ b/ribbon-loadbalancer/src/main/java/com/netflix/loadbalancer/AbstractServerPredicate.java @@ -47,7 +47,7 @@ public abstract class AbstractServerPredicate implements Predicate private final Random random = new Random(); - private final AtomicInteger nextIndex = new AtomicInteger(); + private final AtomicInteger index = new AtomicInteger(0); private final Predicate serverOnlyPredicate = new Predicate() { @Override @@ -147,10 +147,10 @@ public List getEligibleServers(List servers, Object loadBalancer */ private int incrementAndGetModulo(int modulo) { for (;;) { - int current = nextIndex.get(); + int current = index.get(); int next = (current + 1) % modulo; - if (nextIndex.compareAndSet(current, next) && current < modulo) - return current; + if(index.compareAndSet(current,next)) + return next; } }