divijvaidya commented on code in PR #12590: URL: https://github.com/apache/kafka/pull/12590#discussion_r964546851
########## clients/src/main/java/org/apache/kafka/clients/consumer/internals/Fetcher.java: ########## @@ -1933,11 +1941,76 @@ private Map<String, String> topicPartitionTags(TopicPartition tp) { } } + // Visible for testing + void maybeCloseFetchSessions(final Timer timer) { + final Cluster cluster = metadata.fetch(); + final List<RequestFuture<ClientResponse>> requestFutures = new ArrayList<>(); + for (final Map.Entry<Integer, FetchSessionHandler> entry : sessionHandlers.entrySet()) { + final FetchSessionHandler sessionHandler = entry.getValue(); + // set the session handler to notify close. This will set the next metadata request to send close message. + sessionHandler.notifyClose(); + final Integer fetchTargetNodeId = entry.getKey(); + + // Fet + final Node fetchTarget = cluster.nodeById(fetchTargetNodeId); + if (fetchTarget == null || client.isUnavailable(fetchTarget)) { Review Comment: FYI reviewer It is possible that the node is not part of the cluster any more or the connection to that node has been disconnected. In such scenarios, we don't want to try sending a final fetch request to the server. Note that the node is not necessarily the coordinator and could be another broker (such as read replica). The process of choosing a node to establish a fetch session is determined at https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/consumer/internals/Fetcher.java#L1197-L1225 -- 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