You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "alanlau28 (via GitHub)" <gi...@apache.org> on 2026/09/01 19:20:44 UTC

[PR] KAFKA-17777: Flaky KafkaConsumerTest testReturnRecordsDuringRebalance [kafka]

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

   testReturnRecordsDuringRebalance is flaky for the classic consumer due to the
   same heartbeat-vs-application-thread race addressed in KAFKA-16630: a poll() can
   momentarily return no records, or return a buffered record before the rebalance
   assignment has reconciled. As a result the test's single poll(Duration.ZERO)
   calls occasionally returned zero records, and the step that only counted a record
   once the assignment had settled dropped a record that arrived early and then timed
   out waiting for it.
   
   The affected steps now poll until the expected records are returned using
   TestUtils.waitForCondition, and count each polled record independently of the
   assignment check so an early record is no longer lost. This is a test-only change.
   
   The flakiness was reproduced locally at a high rate under a tight repeat loop;
   after the fix the test passed 2000 stress iterations and 300 consecutive full
   test-task runs with no failures.


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


Re: [PR] KAFKA-17777: Flaky KafkaConsumerTest testReturnRecordsDuringRebalance [kafka]

Posted by "lianetm (via GitHub)" <gi...@apache.org>.
lianetm merged PR #23327:
URL: https://github.com/apache/kafka/pull/23327


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


Re: [PR] KAFKA-17777: Flaky KafkaConsumerTest testReturnRecordsDuringRebalance [kafka]

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


##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -2815,7 +2815,14 @@ public void testReturnRecordsDuringRebalance(GroupProtocol groupProtocol) throws
         fetches1.put(t2p0, new FetchInfo(0, 10));
         client.respondFrom(fetchResponse(fetches1), node);
 
-        ConsumerRecords<String, String> records = consumer.poll(Duration.ZERO);
+        // A background heartbeat can complete the fetch concurrently, so a single poll may return

Review Comment:
   nit just to be accurate on the gap, the problem is not really that the HB can complete the fetch, it is that it does it in 2 steps and the app thread and interleave. 
   
   So maybe something along the lines of: `"A background heartbeat poll can retrieve a completed fetch, and then trigger its completion logic in a separate step (to put the data in the buffer). If the app thread poll runs in between, it will find no completed request or buffered data, so it may return empty records on a first poll attempt"`



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