[ 
https://issues.apache.org/jira/browse/FLINK-41797?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Sergey Nuyanzin reassigned FLINK-41797:
---------------------------------------

    Assignee: Aleksandr Savonin

> KafkaSource can silently lose records when poll() throws 
> IllegalStateException with partitions assigned
> -------------------------------------------------------------------------------------------------------
>
>                 Key: FLINK-41797
>                 URL: https://issues.apache.org/jira/browse/FLINK-41797
>             Project: Flink
>          Issue Type: Bug
>          Components: Connectors / Kafka
>            Reporter: Aleksandr Savonin
>            Assignee: Aleksandr Savonin
>            Priority: Critical
>
> {{KafkaPartitionSplitReader.fetch()}} catches every {{IllegalStateException}} 
> from {{KafkaConsumer.poll()}} and returns an empty batch. 
> h3. How records are skipped
> {{poll()}} can throw {{IllegalStateException}} after it has already advanced 
> the position of some partitions:
>  * {{FetchCollector.collectFetch()}} collects the records of partition A and 
> advances A's position.
>  * It then processes the fetch response of partition B. If B carries an error 
> code that the client does not handle, 
> {{FetchCollector.handleInitializeErrors()}} throws {{IllegalStateException}} 
> ("Unexpected error code ... while fetching at offset ...").
>  * {{collectFetch()}} keeps already collected records only when the failure 
> is a {{{}KafkaException{}}}. {{IllegalStateException}} is not a 
> {{{}KafkaException{}}}, so it leaves {{poll()}} and A's records are dropped, 
> while A's position stays advanced.
> Fetch errors that the client handles do not cause this. For example, with 
> {{TOPIC_AUTHORIZATION_FAILED}} on B the same poll returns A's records.
> h3. Reproduction
> We reproduced the skip in memory with the {{FetchCollector}} of kafka-clients 
> 4.2.0. Partition A had a completed fetch with offsets 100-104, partition B 
> had a completed fetch with error code 7 ({{{}REQUEST_TIMED_OUT{}}}). The 
> collect threw {{{}IllegalStateException{}}}, so none of A's records were 
> returned, and A's position was 105 afterwards. The next fetch for A therefore 
> starts at offset 105.
> h3. Impact
> The split reader ignores the exception and keeps polling the same consumer, 
> so the running job never emits offsets 100-104. The offset in the checkpoint 
> comes from the emitted records. Once Flink emits offset 105 and a checkpoint 
> completes with 106 as A's next offset, a restore cannot recover the skipped 
> records, even while Kafka still retains them. The job keeps running and 
> checkpointing, and neither Flink nor the Kafka client logs anything about the 
> skipped records.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to