You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by da...@apache.org on 2024/01/24 12:57:18 UTC
(kafka) branch 3.7 updated: KAFKA-16029: Fix "Unable to find FetchSessionHandler for node X" bug (#15186)
This is an automated email from the ASF dual-hosted git repository.
dajac pushed a commit to branch 3.7
in repository https://gitbox.apache.org/repos/asf/kafka.git
The following commit(s) were added to refs/heads/3.7 by this push:
new f1924353126 KAFKA-16029: Fix "Unable to find FetchSessionHandler for node X" bug (#15186)
f1924353126 is described below
commit f1924353126fdf6aad2ba1f8d0c22dade59360b1
Author: Kirk True <ki...@kirktrue.pro>
AuthorDate: Wed Jan 24 04:53:12 2024 -0800
KAFKA-16029: Fix "Unable to find FetchSessionHandler for node X" bug (#15186)
Change `AbstractFetcher`/`Fetcher` to _not_ clear the `sessionHandlers` cache during `prepareCloseFetchSessionRequests()`.
During `close()`, `Fetcher` calls `maybeCloseFetchSessions()` which, in turn, calls `prepareCloseFetchSessionRequests()` and then calls `NetworkClient.poll()` to complete the requests. Since `prepareCloseFetchSessionRequests()` (erroneously) clears the `sessionHandlers` cache, when the response is processed, the sessions are missing, and the warning is logged.
Reviewers: Andrew Schofield <as...@confluent.io>, David Jacot <dj...@confluent.io>
---
.../clients/consumer/internals/AbstractFetch.java | 28 ++++++++++------------
.../kafka/clients/consumer/internals/Fetcher.java | 11 ++++++++-
2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractFetch.java b/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractFetch.java
index 1d0c9b09f61..73584ce06ff 100644
--- a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractFetch.java
+++ b/clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractFetch.java
@@ -376,25 +376,21 @@ public abstract class AbstractFetch implements Closeable {
final Cluster cluster = metadata.fetch();
Map<Node, FetchSessionHandler.Builder> fetchable = new HashMap<>();
- try {
- sessionHandlers.forEach((fetchTargetNodeId, sessionHandler) -> {
- // set the session handler to notify close. This will set the next metadata request to send close message.
- sessionHandler.notifyClose();
+ sessionHandlers.forEach((fetchTargetNodeId, sessionHandler) -> {
+ // set the session handler to notify close. This will set the next metadata request to send close message.
+ sessionHandler.notifyClose();
- // FetchTargetNode may not be available as it may have disconnected the connection. In such cases, we will
- // skip sending the close request.
- final Node fetchTarget = cluster.nodeById(fetchTargetNodeId);
+ // FetchTargetNode may not be available as it may have disconnected the connection. In such cases, we will
+ // skip sending the close request.
+ final Node fetchTarget = cluster.nodeById(fetchTargetNodeId);
- if (fetchTarget == null || isUnavailable(fetchTarget)) {
- log.debug("Skip sending close session request to broker {} since it is not reachable", fetchTarget);
- return;
- }
+ if (fetchTarget == null || isUnavailable(fetchTarget)) {
+ log.debug("Skip sending close session request to broker {} since it is not reachable", fetchTarget);
+ return;
+ }
- fetchable.put(fetchTarget, sessionHandler.newBuilder());
- });
- } finally {
- sessionHandlers.clear();
- }
+ fetchable.put(fetchTarget, sessionHandler.newBuilder());
+ });
return fetchable.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().build()));
}
diff --git a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/Fetcher.java b/clients/src/main/java/org/apache/kafka/clients/consumer/internals/Fetcher.java
index 51b2532e48b..3c8a9c148db 100644
--- a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/Fetcher.java
+++ b/clients/src/main/java/org/apache/kafka/clients/consumer/internals/Fetcher.java
@@ -150,10 +150,19 @@ public class Fetcher<K, V> extends AbstractFetch {
* be executed once the first time that any of the {@link #close()} methods are called. Subclasses can override
* this method without the need for extra synchronization at the instance level.
*
+ * <p/>
+ *
+ * <em>Note</em>: this method is <code>synchronized</code> to reinstitute the 3.5 behavior:
+ *
+ * <blockquote>
+ * Shared states (e.g. sessionHandlers) could be accessed by multiple threads (such as heartbeat thread), hence,
+ * it is necessary to acquire a lock on the fetcher instance before modifying the states.
+ * </blockquote>
+ *
* @param timer Timer to enforce time limit
*/
// Visible for testing
- protected void closeInternal(Timer timer) {
+ protected synchronized void closeInternal(Timer timer) {
// we do not need to re-enable wake-ups since we are closing already
client.disableWakeups();
maybeCloseFetchSessions(timer);