CURATOR-460 Synchronize access to startOfSuspendedEpoch
authorjavando <antonio.rafael.ar@gmail.com>
Thu, 5 Apr 2018 02:09:10 +0000 (23:09 -0300)
committerjavando <antonio.rafael.ar@gmail.com>
Thu, 5 Apr 2018 02:09:10 +0000 (23:09 -0300)
curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java

index fedcedf..76c5636 100644 (file)
@@ -251,10 +251,18 @@ public class ConnectionStateManager implements Closeable
         {
             try
             {
+
+                long localStartOfSuspendedEpoch;
+
+                synchronized (this) {
+                    localStartOfSuspendedEpoch = this.startOfSuspendedEpoch;
+                }
+
                 int lastNegotiatedSessionTimeoutMs = client.getZookeeperClient().getLastNegotiatedSessionTimeoutMs();
                 int useSessionTimeoutMs = (lastNegotiatedSessionTimeoutMs > 0) ? lastNegotiatedSessionTimeoutMs : sessionTimeoutMs;
-                useSessionTimeoutMs = sessionExpirationPercent > 0 && startOfSuspendedEpoch != 0 ? (useSessionTimeoutMs * sessionExpirationPercent) / 100 : useSessionTimeoutMs;
-                long elapsedMs = startOfSuspendedEpoch == 0 ? useSessionTimeoutMs / 2 : System.currentTimeMillis() - startOfSuspendedEpoch;
+                useSessionTimeoutMs = sessionExpirationPercent > 0 && localStartOfSuspendedEpoch != 0 ? (useSessionTimeoutMs * sessionExpirationPercent) / 100 : useSessionTimeoutMs;
+                long elapsedMs = localStartOfSuspendedEpoch == 0 ? useSessionTimeoutMs / 2 : System.currentTimeMillis() - localStartOfSuspendedEpoch;
+
                 long pollMaxMs = useSessionTimeoutMs - elapsedMs;
 
                 final ConnectionState newState = eventQueue.poll(pollMaxMs, TimeUnit.MILLISECONDS);