kirktrue commented on code in PR #16686: URL: https://github.com/apache/kafka/pull/16686#discussion_r1752972613
########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java: ########## @@ -1302,6 +1304,42 @@ private void releaseAssignmentAndLeaveGroup(final Timer timer) { } } + /** + * The unsubscribe process requires a handful of back-and-forth trips between the application thread and + * the background thread: + * + * <ol> + * <li> + * Application thread: enqueue {@link UnsubscribeEvent} + * </li> + * <li> + * Background thread: process {@link UnsubscribeEvent} and + * enqueue {@link ConsumerRebalanceListenerCallbackNeededEvent} + * </li> + * <li> + * Application thread: process {@link ConsumerRebalanceListenerCallbackNeededEvent}, + * invoke appropriate {@link ConsumerRebalanceListener} method, and + * enqueue {@link ConsumerRebalanceListenerCallbackCompletedEvent} + * </li> + * <li> + * Background thread: process {@link ConsumerRebalanceListenerCallbackCompletedEvent} and + * enqueue {@link NetworkClientDelegate.UnsentRequest} to send the + * {@link ConsumerGroupHeartbeatRequest} to leave the consumer group + * </li> + * </ol> + * + * In cases where the incoming {@link Timer timer} has very little remaining time, e.g. 0, it is impossible + * to perform the thread switches necessary to leave the group. Therefore, in cases where there isn't much + * of a timeout left, increase it slightly (presently 1000 ms.) to improve the chances for the consumer to + * properly leave the group. Review Comment: I've submitted two new Jiras: 1. KAFKA-17518: AsyncKafkaConsumer cannot reliably leave group when closed with small timeout 2. KAFKA-17519: Define and validate correctness of Consumer.close() and its timeout when thread is interrupted -- 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