You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Jason Gustafson (Jira)" <ji...@apache.org> on 2022/01/03 19:23:00 UTC

[jira] [Commented] (KAFKA-13574) NotLeaderOrFollowerException thrown for a successful send

    [ https://issues.apache.org/jira/browse/KAFKA-13574?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17468160#comment-17468160 ] 

Jason Gustafson commented on KAFKA-13574:
-----------------------------------------

[~aphyr] Thanks for the bug report. My guess is that you might be hitting a race condition such as the following during a leader change:

1. Leader takes the write at offset N and parks the request in purgatory to await replication.
2. Follower acks offset N-1 and writes the data up to offset N.
3. Follower becomes new leader before it is able to ack offset N.
4. Old leader sees the leader change and returns NOT_LEADER to the still-parked produce request.

In this scenario, the new leader has the data and it may become committed even though the produce request returned NOT_LEADER. There might be a better error to return in this scenario, but we do want the producer to realize that it needs to find the new leader. I guess we could also hold the request a bit longer until we know whether or not it was committed. Failing that, we should make it clear that NOT_LEADER does not necessarily indicate a failure to write the data.

[~junrao] Any thoughts?



> NotLeaderOrFollowerException thrown for a successful send
> ---------------------------------------------------------
>
>                 Key: KAFKA-13574
>                 URL: https://issues.apache.org/jira/browse/KAFKA-13574
>             Project: Kafka
>          Issue Type: Bug
>          Components: clients
>    Affects Versions: 3.0.0
>         Environment: openjdk version "11.0.13" 2021-10-19
>            Reporter: Kyle Kingsbury
>            Priority: Minor
>              Labels: error-handling
>
> With org.apache.kafka/kafka-clients 3.0.0, under rare circumstances involving multiple node and network failures, I've observed a call to `producer.send()` throw `NotLeaderOrFollowerException` for a message which later appears in `consumer.poll()` return values.
> I don't have a reliable repro case for this yet, but the case I hit involved retries=1000, acks=all, and idempotence enabled. I suspect what might be happening here is that an initial attempt to send the message makes it to the server and is committed, but the acknowledgement is lost e.g. due to timeout; the Kafka producer then automatically retries the send attempt, and on that retry hits a NotLeaderOrFollowerException, which is thrown back to the caller. If we interpret NotLeaderOrFollowerException as a definite failure, then this would constitute an aborted read.
> I've seen issues like this in a number of databases around client or server-internal retry mechanisms, and I think the thing to do is: rather than throwing the most *recent* error, throw the {*}most indefinite{*}. That way clients know that their request may have actually succeeded, and they won't (e.g.) attempt to re-submit a non-idempotent request again.
> As a side note: is there... perhaps documentation on which errors in Kafka are supposed to be definite vs indefinite? NotLeaderOrFollowerException is a subclass of RetriableException, but it looks like RetriableException is more about transient vs permanent errors than whether it's safe to retry.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)