Repository: apache/kafka
File: clients/src/main/java/org/apache/kafka/clients/consumer/internals/AbstractHeartbeatRequestManager.java (Java)

Code before:
                        heartbeatRequestName(), membershipManager().memberId());
                logInfo(message, response, currentTimeMs);
                membershipManager().transitionToFenced();
                // Skip backoff so that a next HB to rejoin is sent as soon as the fenced member releases its assignment
                heartbeatRequestState.reset();
                break;

            case INVALID_REGULAR_EXPRESSION:
                logger.error("{} failed due to {}: {}", heartbeatRequestName(), error, errorMessage);
                handleFatalFailure(error.exception("Invalid RE2J SubscriptionPattern provided in the call to " +
                    "subscribe. " + errorMessage));
                break;

            case GROUP_ID_NOT_FOUND:
                // If the group doesn't exist (e.g., member never joined due to InvalidTopicException),
                // GROUP_ID_NOT_FOUND should be ignored - the leave is effectively complete.
                // When a leave heartbeat (epoch=-1) is sent, the state transitions synchronously
                // from LEAVING to UNSUBSCRIBED in onHeartbeatRequestGenerated() before the request is sent.
                if (membershipManager().state() == MemberState.UNSUBSCRIBED) {
                    logger.info("{} received GROUP_ID_NOT_FOUND for group {} while unsubscribed. " +
                            "Not treating as fatal since consumer is leaving group.",
                            heartbeatRequestName(), membershipManager().groupId());
                    membershipManager().onHeartbeatRequestSkipped();
                } else {
                    // Else, this is a fatal error, we should throw it and transition to fatal state.
                    logger.error("{} failed due to unexpected error {}: {}",
                            heartbeatRequestName(), error, errorMessage);
                    handleFatalFailure(error.exception(errorMessage));
                }
                break;
            default:
                if (!handleSpecificExceptionInResponse(response, currentTimeMs)) {
                    // If the manager receives an unknown error - there could be a bug in the code or a new error code
                    logger.error("{} failed due to unexpected error {}: {}", heartbeatRequestName(), error, errorMessage);
                    handleFatalFailure(error.exception(errorMessage));
                }
                break;
        }

        // Notify the group manager about the failure after all errors have been handled and propagated.
        membershipManager().onHeartbeatFailure(false);
    }

    protected void logInfo(final String message, final R response, final long currentTimeMs) {
        logger.info("{} in {}ms: {}",
            message,
            heartbeatRequestState.remainingBackoffMs(currentTimeMs),
            errorMessageForResponse(response));
    }

    protected void handleFatalFailure(Throwable error) {

Review comment (suggestion):
nit: The following `logger.error` is identical but on a single line. Please change this to a single line also.

Code after:
                        heartbeatRequestName(), membershipManager().memberId());
                logInfo(message, response, currentTimeMs);
                membershipManager().transitionToFenced();
                // Skip backoff so that a next HB to rejoin is sent as soon as the fenced member releases its assignment
                heartbeatRequestState.reset();
                break;

            case INVALID_REGULAR_EXPRESSION:
                logger.error("{} failed due to {}: {}", heartbeatRequestName(), error, errorMessage);
                handleFatalFailure(error.exception("Invalid RE2J SubscriptionPattern provided in the call to " +
                    "subscribe. " + errorMessage));
                break;

            case GROUP_ID_NOT_FOUND:
                // If the group doesn't exist (e.g., member never joined due to InvalidTopicException),
                // GROUP_ID_NOT_FOUND should be ignored - the leave is effectively complete.
                // When a leave heartbeat (epoch=-1) is sent, the state transitions synchronously
                // from LEAVING to UNSUBSCRIBED in onHeartbeatRequestGenerated() before the request is sent.
                if (membershipManager().state() == MemberState.UNSUBSCRIBED) {
                    logger.info("{} received GROUP_ID_NOT_FOUND for group {} while unsubscribed. ",
                            heartbeatRequestName(), membershipManager().groupId());
                    membershipManager().onHeartbeatRequestSkipped();
                } else {
                    // Else, this is a fatal error, we should throw it and transition to fatal state.
                    logger.error("{} failed due to unexpected error {}: {}", heartbeatRequestName(), error, errorMessage);
                    handleFatalFailure(error.exception(errorMessage));
                }
                break;

            default:
                if (!handleSpecificExceptionInResponse(response, currentTimeMs)) {
                    // If the manager receives an unknown error - there could be a bug in the code or a new error code
                    logger.error("{} failed due to unexpected error {}: {}", heartbeatRequestName(), error, errorMessage);
                    handleFatalFailure(error.exception(errorMessage));
                }
                break;
        }

        // Notify the group manager about the failure after all errors have been handled and propagated.
        membershipManager().onHeartbeatFailure(false);
    }

    protected void logInfo(final String message, final R response, final long currentTimeMs) {
        logger.info("{} in {}ms: {}",
            message,
            heartbeatRequestState.remainingBackoffMs(currentTimeMs),
            errorMessageForResponse(response));
    }

    protected void handleFatalFailure(Throwable error) {
        backgroundEventHandler.add(new ErrorEvent(error));