diff --git a/flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/TestingListener.java b/flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/TestingListener.java index 87decc7bddfd8b863c9f64e2d5f42eac2225d292..85715054d173f8b0f7891607cea157b7c85e41e0 100644 --- a/flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/TestingListener.java +++ b/flink-runtime/src/test/java/org/apache/flink/runtime/leaderelection/TestingListener.java @@ -51,11 +51,11 @@ public class TestingListener implements LeaderRetrievalListener { long start = System.currentTimeMillis(); long curTimeout; - while ( + synchronized (lock) { + while ( exception == null && - (address == null || address.equals(oldAddress)) && - (curTimeout = timeout - System.currentTimeMillis() + start) > 0) { - synchronized (lock) { + (address == null || address.equals(oldAddress)) && + (curTimeout = timeout - System.currentTimeMillis() + start) > 0) { try { lock.wait(curTimeout); } catch (InterruptedException e) {