kirktrue commented on code in PR #15640:
URL: https://github.com/apache/kafka/pull/15640#discussion_r1579897029


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/events/CompletableApplicationEvent.java:
##########
@@ -36,13 +36,14 @@ protected CompletableApplicationEvent(final Type type, 
final Timer timer) {
         super(type);
         this.future = new CompletableFuture<>();
         Objects.requireNonNull(timer);
-        this.deadlineMs = timer.remainingMs() + timer.currentTimeMs();
-    }
 
-    protected CompletableApplicationEvent(final Type type, final long 
deadlineMs) {
-        super(type);
-        this.future = new CompletableFuture<>();
-        this.deadlineMs = deadlineMs;
+        long currentTimeMs = timer.currentTimeMs();
+        long remainingMs = timer.remainingMs();
+
+        if (currentTimeMs > Long.MAX_VALUE - remainingMs)
+            this.deadlineMs = Long.MAX_VALUE;
+        else
+            this.deadlineMs = currentTimeMs + remainingMs;

Review Comment:
   For point 1, I created a new method named `calculateDeadlineMs` that moves 
this code into one place.
   
   For point 2, there is no `Timer` in the event because `Timer` is not thread 
safe, and events cross the application/background thread boundary. I did not 
want to expose the `Timer` in the event to avoid its possible usage from the 
background thread.



-- 
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-unsubscr...@kafka.apache.org

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

Reply via email to