adikou commented on code in PR #24226:
URL: https://github.com/apache/kafka/pull/24226#discussion_r4591906712


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractHeartbeatRequestManager.java:
##########
@@ -318,16 +319,47 @@ private NetworkClientDelegate.UnsentRequest 
makeHeartbeatRequest(final boolean i
             return logResponse(request);
         else
             return request.whenComplete((response, exception) -> {
+                // Handle unexpected errors when processing a HB response, so 
that
+                // the member moves to a fatal state and the error reaches the 
application.
                 long completionTimeMs = request.handler().completionTimeMs();
-                if (response != null) {
-                    
metricsManager.recordRequestLatency(response.requestLatencyMs());
-                    onResponse((R) response.responseBody(), completionTimeMs);
-                } else {
-                    onFailure(exception, completionTimeMs);
+                try {
+                    if (response != null) {
+                        
metricsManager.recordRequestLatency(response.requestLatencyMs());
+                        onResponse((R) response.responseBody(), 
completionTimeMs);
+                    } else {
+                        onFailure(exception, completionTimeMs);
+                    }
+                } catch (Throwable t) {
+                    onUnexpectedResponseHandlingError(t, completionTimeMs);
                 }
             });
     }
 
+    /**
+     * Handle an unexpected error thrown while handling a heartbeat response 
or a heartbeat request
+     * failure. This would be the case of a bug on the client or an 
unexpected/buggy response from the broker.
+     * The member transitions to {@link MemberState#FATAL} and the error is 
propagated to the application
+     * (just like any other fatal heartbeat error).
+     */
+    private void onUnexpectedResponseHandlingError(final Throwable error, 
final long currentTimeMs) {
+        String errorMessage = String.format("Unexpected error while handling 
%s: %s",
+            heartbeatRequestName(), error);

Review Comment:
   We're including the error already in the log line below which logs the 
proper msg+stacktrace. I think we can skip it here and just switch to string 
concat



-- 
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