This is an automated email from the ASF dual-hosted git repository.
kezhuw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/curator.git
The following commit(s) were added to refs/heads/master by this push:
new 81bf992c1 GH-1290: Fix barrier bypass in DistributedDoubleBarrier due
to spurious wakeups or SyncConnected events
81bf992c1 is described below
commit 81bf992c10f51584cc4452e04f88c79ce8d7feb2
Author: Dylan Cao <[email protected]>
AuthorDate: Sun Jul 19 13:23:47 2026 -0400
GH-1290: Fix barrier bypass in DistributedDoubleBarrier due to spurious
wakeups or SyncConnected events
Fixes #1290.
---
.../recipes/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 class DistributedDoubleBarrier {
connectionLost.set(event.getState() !=
Event.KeeperState.SyncConnected);
client.runSafe(() -> {
synchronized (DistributedDoubleBarrier.this) {
- hasBeenNotified.set(true);
DistributedDoubleBarrier.this.notifyAll();
}
});
@@ -253,8 +251,7 @@ public class DistributedDoubleBarrier {
}
private synchronized boolean internalEnter(long startMs, boolean
hasMaxWait, long maxWaitMs) throws Exception {
- boolean result = true;
- do {
+ while (true) {
List<String> children = getChildrenForEntering();
int count = (children != null) ? children.size() : 0;
if (count >= memberQty) {
@@ -263,26 +260,19 @@ public class DistributedDoubleBarrier {
} 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;
+ }
}
}