Skip to content

Conversation

@xingsuo-zbz
Copy link
Contributor

@xingsuo-zbz xingsuo-zbz commented Feb 25, 2025

Fix bug of useSessionTimeoutMs overflow.

This closes #1248.

@xingsuo-zbz
Copy link
Contributor Author

Hi, @tisonkun Could you please help me review it?

@tisonkun tisonkun changed the title [CURATOR-731] Fix bug of useSessionTimeoutMs overflow GH-1248. Fix bug of useSessionTimeoutMs overflow Feb 26, 2025
Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the usage I suppose we can simply change the signature of getUseSessionTimeoutMs to return a long and use long inside.

@tisonkun
Copy link
Member

Something like this:

diff --git a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
index ac963a21..c751296d 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/state/ConnectionStateManager.java
@@ -241,7 +241,7 @@ public class ConnectionStateManager implements Closeable {
     private void processEvents() {
         while (state.get() == State.STARTED) {
             try {
-                int useSessionTimeoutMs = getUseSessionTimeoutMs();
+                long useSessionTimeoutMs = getUseSessionTimeoutMs();
                 long elapsedMs = startOfSuspendedEpoch == 0
                         ? useSessionTimeoutMs / 2
                         : System.currentTimeMillis() - startOfSuspendedEpoch;
@@ -281,7 +281,7 @@ public class ConnectionStateManager implements Closeable {
     private void checkSessionExpiration() {
         if ((currentConnectionState == ConnectionState.SUSPENDED) && (startOfSuspendedEpoch != 0)) {
             long elapsedMs = System.currentTimeMillis() - startOfSuspendedEpoch;
-            int useSessionTimeoutMs = getUseSessionTimeoutMs();
+            long useSessionTimeoutMs = getUseSessionTimeoutMs();
             if (elapsedMs >= useSessionTimeoutMs) {
                 startOfSuspendedEpoch =
                         System.currentTimeMillis(); // reset startOfSuspendedEpoch to avoid spinning on this session
@@ -317,9 +317,9 @@ public class ConnectionStateManager implements Closeable {
         startOfSuspendedEpoch = (currentConnectionState == ConnectionState.SUSPENDED) ? System.currentTimeMillis() : 0;
     }
 
-    private int getUseSessionTimeoutMs() {
-        int lastNegotiatedSessionTimeoutMs = client.getZookeeperClient().getLastNegotiatedSessionTimeoutMs();
-        int useSessionTimeoutMs =
+    private long getUseSessionTimeoutMs() {
+        long lastNegotiatedSessionTimeoutMs = client.getZookeeperClient().getLastNegotiatedSessionTimeoutMs();
+        long useSessionTimeoutMs =
                 (lastNegotiatedSessionTimeoutMs > 0) ? lastNegotiatedSessionTimeoutMs : sessionTimeoutMs;
         useSessionTimeoutMs = sessionExpirationPercent > 0 && startOfSuspendedEpoch != 0
                 ? (useSessionTimeoutMs * sessionExpirationPercent) / 100

@xingsuo-zbz xingsuo-zbz force-pushed the bugfix/useSessionTimeoutMs-overflow branch from 39cf51a to e50507c Compare February 27, 2025 02:55
@xingsuo-zbz
Copy link
Contributor Author

@tisonkun thanks,Changes done as discussed. Please review again.

@tisonkun tisonkun requested review from eolivelli and kezhuw February 27, 2025 03:09
@tisonkun tisonkun merged commit 0bb3adf into apache:master Feb 28, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CuratorZookeeperClient were reset unexpectedly

3 participants