FrankYang0529 commented on code in PR #17411:
URL: https://github.com/apache/kafka/pull/17411#discussion_r1795758832


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java:
##########
@@ -1277,10 +1278,13 @@ private void releaseAssignmentAndLeaveGroup(final Timer 
timer) {
         UnsubscribeEvent unsubscribeEvent = new 
UnsubscribeEvent(calculateDeadlineMs(timer));
         applicationEventHandler.add(unsubscribeEvent);
         try {
-            // If users subscribe to an invalid topic name, they will get 
InvalidTopicException in error events,
-            // because network thread keeps trying to send MetadataRequest in 
the background.
-            // Ignore it to avoid unsubscribe failed.
-            processBackgroundEvents(unsubscribeEvent.future(), timer, e -> e 
instanceof InvalidTopicException);
+            // Network thread keeps trying to send MetadataRequest in the 
background.
+            // If there is invalid request, there will have many error events. 
We would like to ignore it to avoid unsubscribe fail.
+            // Ignore exceptions:
+            // InvalidTopicException: avoid invalid topic name.
+            // UnsupportedVersionException: avoid sending consumer group 
protocol to unsupported broker.
+            processBackgroundEvents(unsubscribeEvent.future(), timer,
+                    e -> e instanceof InvalidTopicException || e instanceof 
UnsupportedVersionException);

Review Comment:
   It's to handle the case where `close()` attempts to unsubscribe and previous 
`MetadataRequest` hits `UnsupportedVersionException`.
   
   When we do `AbstractMembershipManager#leaveGroup`, the consumer is not in a 
group, so it only does `subscriptions.unsubscribe()` and return.
   
   
https://github.com/apache/kafka/blob/dcd3bbe5929d9ee558a16de04c99c504c8c1c3ac/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractMembershipManager.java#L544-L552



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to