From 65906ec1bfd220f11e003eb38189a9a33458c5bb Mon Sep 17 00:00:00 2001 From: Dylan Cao Date: Thu, 12 Mar 2026 15:24:57 -0400 Subject: [PATCH] Fix double barrier spurious entry --- .../barriers/DistributedDoubleBarrier.java | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/barriers/DistributedDoubleBarrier.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/barriers/DistributedDoubleBarrier.java index 747a9d6b0..960468b99 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/barriers/DistributedDoubleBarrier.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/barriers/DistributedDoubleBarrier.java @@ -57,7 +57,6 @@ public class DistributedDoubleBarrier { private final int memberQty; private final String ourPath; private final String readyPath; - private final AtomicBoolean hasBeenNotified = new AtomicBoolean(false); private final AtomicBoolean connectionLost = new AtomicBoolean(false); private final Watcher watcher = new Watcher() { @Override @@ -65,7 +64,6 @@ public void process(WatchedEvent event) { connectionLost.set(event.getState() != Event.KeeperState.SyncConnected); client.runSafe(() -> { synchronized (DistributedDoubleBarrier.this) { - hasBeenNotified.set(true); DistributedDoubleBarrier.this.notifyAll(); } }); @@ -253,8 +251,7 @@ private void checkDeleteOurPath(boolean shouldExist) throws Exception { } private synchronized boolean internalEnter(long startMs, boolean hasMaxWait, long maxWaitMs) throws Exception { - boolean result = true; - do { + while (true) { List children = getChildrenForEntering(); int count = (children != null) ? children.size() : 0; if (count >= memberQty) { @@ -263,26 +260,19 @@ private synchronized boolean internalEnter(long startMs, boolean hasMaxWait, lon } catch (KeeperException.NodeExistsException ignore) { // ignore } - break; + return true; } - if (hasMaxWait && !hasBeenNotified.get()) { + if (hasMaxWait) { long elapsed = System.currentTimeMillis() - startMs; long thisWaitMs = maxWaitMs - elapsed; if (thisWaitMs <= 0) { - result = false; - } else { - wait(thisWaitMs); - } - - if (!hasBeenNotified.get()) { - result = false; + return false; } + wait(thisWaitMs); } else { wait(); } - } while (false); - - return result; + } } }