public void transitionToSendingLeaveGroup(boolean dueToExpiredPollTimer) {
        if (state == MemberState.FATAL) {
            log.warn("Member {} with epoch {} won't send leave group request because it is in " +
                    "FATAL state", memberId, memberEpoch);
            return;
        }
        if (state == MemberState.UNSUBSCRIBED) {
            log.warn("Member {} won't send leave group request because it is already out of the group.",
                    memberId);
            return;
        }

        if (dueToExpiredPollTimer) {
            this.isPollTimerExpired = true;

            // Briefly transition through prepare leaving. The member does not have to release
            // any assignment before sending the leave group given that is stale. It will invoke
            // onPartitionsLost after sending the leave group on the STALE state.
            transitionTo(MemberState.PREPARE_LEAVING);
        }
        updateMemberEpoch(ShareGroupHeartbeatRequest.LEAVE_GROUP_MEMBER_EPOCH);
        currentAssignment = new HashMap<>();
        transitionTo(MemberState.LEAVING);
    }
Reset member epoch to the value required for the leave the group heartbeat request, and
transition to the {@link MemberState#LEAVING} state so that a heartbeat
request is sent out with it.

@param dueToExpiredPollTimer True if the leave group is due to an expired poll timer. This
                             will indicate that the member must remain STALE after leaving,
                             until it releases its assignment and the timer is reset.
clients/src/main/java/org/apache/kafka/clients/consumer/internals/ShareMembershipManager.java