philipnee commented on code in PR #14842:
URL: https://github.com/apache/kafka/pull/14842#discussion_r1407198957


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ConsumerNetworkThread.java:
##########
@@ -269,60 +275,56 @@ void cleanup() {
      * completed in time.
      */
     // Visible for testing
-    void maybeAutoCommitAndLeaveGroup(final Timer timer) {
+    void maybeAutocommitOnClose(final Timer timer) {
         if (!requestManagers.coordinatorRequestManager.isPresent())
             return;
 
+        if (!requestManagers.commitRequestManager.isPresent()) {
+            log.error("Expecting a CommitRequestManager but the object was 
never initialized. Shutting down.");
+            return;
+        }
+
+        if (!requestManagers.commitRequestManager.get().canAutoCommit()) {
+            return;
+        }
+
         ensureCoordinatorReady(timer);
-        List<NetworkClientDelegate.UnsentRequest> tasks = closingRequests();
-        networkClientDelegate.addAll(tasks);
+        List<NetworkClientDelegate.UnsentRequest> autocommitRequest =
+            
Collections.singletonList(requestManagers.commitRequestManager.get().commitAllConsumedPositions());
+        networkClientDelegate.addAll(autocommitRequest);
         do {
             long currentTimeMs = timer.currentTimeMs();
             ensureCoordinatorReady(timer);
             networkClientDelegate.poll(timer.remainingMs(), currentTimeMs);
-        } while (timer.notExpired() && !tasks.stream().allMatch(v -> 
v.future().isDone()));
+        } while (timer.notExpired() && 
!autocommitRequest.get(0).future().isDone());
+    }
+
+    void maybeLeaveGroup(final Timer timer) {
+        // TODO: Leave group upon closing the consumer
     }
 
     private void ensureCoordinatorReady(final Timer timer) {
-        while (!coordinatorReady()) {
+        while (!coordinatorReady() && timer.notExpired()) {
             findCoordinatorSync(timer);
         }
     }
 
     private boolean coordinatorReady() {
-        CoordinatorRequestManager coordinatorRequestManager = 
requestManagers.coordinatorRequestManager.get();
+        CoordinatorRequestManager coordinatorRequestManager = 
requestManagers.coordinatorRequestManager.orElseThrow(
+                () -> new IllegalStateException("CoordinatorRequestManager 
uninitialized."));

Review Comment:
   Probably unnecessary - but adding this for a safety check wdyt?



-- 
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