[
https://issues.apache.org/jira/browse/FLINK-41797?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Aleksandr Savonin updated FLINK-41797:
--------------------------------------
Description:
{{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.
was:
KafkaPartitionSplitReader.fetch() catches every IllegalStateException from
KafkaConsumer.poll() and returns an empty batch.
It also hides poll failures while the consumer still has assigned partitions.
We reproduced the skip in memory with Kafka 4.2.0’s FetchCollector. During one
fetch, Kafka advanced partition A past offsets 100–104, then threw
IllegalStateException while processing a fetch error for partition B. The fetch
returned no records. When consumption continued with the same consumer state,
the next record delivered from A was at offset 105.
If Flink processes offset 105 and a subsequent checkpoint completes with 106 as
A’s next offset, restoring from that checkpoint skips records 100–104 even
while Kafka still retains them. The job can therefore keep running and
checkpointing without reporting that downstream missed five records.
Expected behavior: When partitions are assigned, the reader should propagate
the original IllegalStateException so Flink can apply the job’s restart
strategy. When an empty bounded split leaves the consumer with no assigned
partitions, the reader should continue to report that split as finished.
> 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
> 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)