lianetm commented on code in PR #15585: URL: https://github.com/apache/kafka/pull/15585#discussion_r1550279550
########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/AsyncKafkaConsumer.java: ########## @@ -1750,8 +1753,14 @@ private void subscribeInternal(Pattern pattern, Optional<ConsumerRebalanceListen throwIfNoAssignorsConfigured(); log.info("Subscribed to pattern: '{}'", pattern); subscriptions.subscribe(pattern, listener); - updatePatternSubscription(metadata.fetch()); metadata.requestUpdateForNewTopics(); + Cluster cache = metadata.fetch(); + + while (cache == metadata.fetch()) { + log.info("Waiting for new metadata update"); + } Review Comment: btw, the moment we move the event generation to the point where the subscription is updated inside the `updatePatternSubscription`, I expect you won't get the error you mentioned [here](https://github.com/apache/kafka/pull/15585#issuecomment-2021526537) that made you introduce the while loop: > there is a race condition bug where the metadata is not updated but the heartbeat request is already created, but it lacks required info -- 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