You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2023/01/10 03:59:26 UTC

[GitHub] [kafka] showuon opened a new pull request, #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

showuon opened a new pull request, #13099:
URL: https://github.com/apache/kafka/pull/13099

   *More detailed description of your change,
   if necessary. The PR title and PR message become
   the squashed commit message, so use a separate
   comment to ping reviewers.*
   
   *Summary of testing strategy (including rationale)
   for the feature or bug fix. Unit and/or integration
   tests are expected for any behaviour change and
   system tests should be considered for larger changes.*
   
   ### Committer Checklist (excluded from commit message)
   - [ ] Verify design and implementation 
   - [ ] Verify test coverage and CI build status
   - [ ] Verify documentation (including upgrade notes)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] showuon commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by "showuon (via GitHub)" <gi...@apache.org>.
showuon commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1098593071


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE

Review Comment:
   Updated with javadoc. Thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] ijuma commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by GitBox <gi...@apache.org>.
ijuma commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1070520573


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {
+        long result = Long.MAX_VALUE;
+        try {
+            result = Math.addExact(a, b);
+        } catch (ArithmeticException e) {
+            log.info("The sum of {} and {} is overflowed, set to Long.MAX_VALUE", a, b);

Review Comment:
   If it's a real configuration problem, an exception should be thrown. By the time a user sees the log, it's often too late.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] ijuma commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by GitBox <gi...@apache.org>.
ijuma commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1073567726


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {
+        long result = Long.MAX_VALUE;
+        try {
+            result = Math.addExact(a, b);
+        } catch (ArithmeticException e) {
+            log.info("The sum of {} and {} is overflowed, set to Long.MAX_VALUE", a, b);

Review Comment:
   If it's not an issue, why are we logging it at info level? Either we just handle it automatically or we throw an exception. That's why I mentioned "real configuration problems" should throw an exception.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] showuon commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by "showuon (via GitHub)" <gi...@apache.org>.
showuon commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1098593520


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {
+        long result = Long.MAX_VALUE;
+        try {
+            result = Math.addExact(a, b);
+        } catch (ArithmeticException e) {
+            log.info("The sum of {} and {} is overflowed, set to Long.MAX_VALUE", a, b);

Review Comment:
   Updated. Now it'll throw exception. Thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] showuon commented on pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by GitBox <gi...@apache.org>.
showuon commented on PR #13099:
URL: https://github.com/apache/kafka/pull/13099#issuecomment-1376733175

   @rondagostino , please take a look. Thanks.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] showuon commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1073368235


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {
+        long result = Long.MAX_VALUE;
+        try {
+            result = Math.addExact(a, b);
+        } catch (ArithmeticException e) {
+            log.info("The sum of {} and {} is overflowed, set to Long.MAX_VALUE", a, b);

Review Comment:
   Setting an upper bound is a good idea, maybe 1 year? Anyway, that would need a KIP to address that. We can treat it as a separate idea. 
   
   > If it's a real configuration problem, an exception should be thrown. By the time a user sees the log, it's often too late.
   
   Is it really an issue? I mean, setting a `Long.Max_VALUE ms` as expiration = setting it expired after 292,471,208 years. Does it really matter if we only expired it after 290,000,000 years?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] divijvaidya commented on pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by "divijvaidya (via GitHub)" <gi...@apache.org>.
divijvaidya commented on PR #13099:
URL: https://github.com/apache/kafka/pull/13099#issuecomment-1594751739

   @showuon rebase from trunk please?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] showuon commented on pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by "showuon (via GitHub)" <gi...@apache.org>.
showuon commented on PR #13099:
URL: https://github.com/apache/kafka/pull/13099#issuecomment-1420692624

   @ijuma @tombentley @clolov , I've updated the PR to throw exception when overflowed. Please take a look again. Thank you.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] tombentley commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by GitBox <gi...@apache.org>.
tombentley commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1066808165


##########
clients/src/test/java/org/apache/kafka/common/security/authenticator/SaslServerAuthenticatorTest.java:
##########
@@ -243,6 +243,40 @@ public void testSessionExpiresAtTokenExpiry() throws IOException {
         }
     }
 
+    @Test
+    public void testSessionWontExpiresWithLargeExpirationTime() throws IOException {

Review Comment:
   ```suggestion
       public void testSessionWontExpireWithLargeExpirationTime() throws IOException {
   ```



##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE

Review Comment:
   Any reason for this not to be a Javadoc?



##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {
+        long result = Long.MAX_VALUE;
+        try {
+            result = Math.addExact(a, b);
+        } catch (ArithmeticException e) {
+            log.info("The sum of {} and {} is overflowed, set to Long.MAX_VALUE", a, b);

Review Comment:
   I think this needs more context: If this gets logged how it the reader of the log supposed to know what went wrong?
   
   Perhaps the way to do it is just to check whether end result of the overall calculation is `Long.MAX_VALUE` and log the message then. Perhaps it should be a `warn` too, since it indicates a configuration problem that really should be fixed; if so we might want to log it only once.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] showuon commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1065331903


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {

Review Comment:
   The method name is copied from guava's [LongMath class](https://guava.dev/releases/20.0/api/docs/com/google/common/math/LongMath.html#saturatedAdd-long-long-).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] showuon commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by GitBox <gi...@apache.org>.
showuon commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1082162567


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {
+        long result = Long.MAX_VALUE;
+        try {
+            result = Math.addExact(a, b);
+        } catch (ArithmeticException e) {
+            log.info("The sum of {} and {} is overflowed, set to Long.MAX_VALUE", a, b);

Review Comment:
   Hmm. OK. Let's throw an exception. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] clolov commented on a diff in pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by GitBox <gi...@apache.org>.
clolov commented on code in PR #13099:
URL: https://github.com/apache/kafka/pull/13099#discussion_r1073321039


##########
clients/src/main/java/org/apache/kafka/common/utils/Utils.java:
##########
@@ -1496,4 +1496,32 @@ public static String replaceSuffix(String str, String oldSuffix, String newSuffi
             throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
         return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
     }
+
+    public static long zeroIfNegative(long value) {
+        return Math.max(0L, value);
+    }
+
+    // returns the sum of a and b unless it would overflow, which will return Long.MAX_VALUE
+    public static long saturatedAdd(long a, long b) {
+        long result = Long.MAX_VALUE;
+        try {
+            result = Math.addExact(a, b);
+        } catch (ArithmeticException e) {
+            log.info("The sum of {} and {} is overflowed, set to Long.MAX_VALUE", a, b);

Review Comment:
   Following Ismael's comment, isn't it wiser to also put an upper bound on https://kafka.apache.org/documentation/#brokerconfigs_connections.max.reauth.ms? As far as I understand the documentation if a client wants to never be forced to reauthenticate they need to just use the default value of 0?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [kafka] github-actions[bot] commented on pull request #13099: KAFKA-14604: avoid SASL session expiration time overflowed when calculation

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #13099:
URL: https://github.com/apache/kafka/pull/13099#issuecomment-1585816407

   This PR is being marked as stale since it has not had any activity in 90 days. If you would like to keep this PR alive, please ask a committer for review. If the PR has  merge conflicts, please update it with the latest from trunk (or appropriate release branch) <p> If this PR is no longer valid or desired, please feel free to close it. If no activity occurrs in the next 30 days, it will be automatically closed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org