[
https://issues.apache.org/jira/browse/KAFKA-21700?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Lianet Magrans resolved KAFKA-21700.
------------------------------------
Resolution: Fixed
> Sender may still send a pending InitProducerId after KafkaProducer is
> force-closed
> ----------------------------------------------------------------------------------
>
> Key: KAFKA-21700
> URL: https://issues.apache.org/jira/browse/KAFKA-21700
> Project: Kafka
> Issue Type: Bug
> Components: clients
> Reporter: Rui Fan
> Assignee: Rui Fan
> Priority: Major
> Fix For: 4.5.0
>
>
> After {{{}KafkaProducer#close(Duration.ZERO){}}}, the Sender I/O thread can
> still send a pending {{InitProducerId}} to the broker.
> Cause: the Sender does not check {{forceClose}} while it waits for the
> coordinator in {{awaitNodeReady}} (via {{{}NetworkClientUtils.awaitReady{}}})
> or during the retry backoff. When the coordinator connection becomes ready,
> the queued request is sent although the producer is already closed.
> Impact: the late request bumps the epoch of the transactional.id and aborts
> the ongoing transaction of a newer producer that took over the same
> transactional.id, which then fails with {{{}ProducerFencedException{}}}.
> Plain EOS: a spurious fence/abort of the newer producer; the data is
> reprocessed.
> 2PC
> ([KIP-939|https://cwiki.apache.org/confluence/display/KAFKA/KIP-939%3A+Support+Participation+in+2PC],
>
> [FLIP-319|https://cwiki.apache.org/confluence/display/FLINK/FLIP-319%3A+Integrate+with+Kafka%27s+Support+for+Proper+2PC+Participation+%28KIP-939%29]):
> the aborted transaction may already be prepared, and the external
> coordinator (e.g. a Flink checkpoint) treats it as committed, so its data is
> lost. We hit this in Flink: a cancelled task's force-closed producer fenced
> the new task attempt.
> Proposed fix: stop waiting in {{awaitReady}} when {{forceClose}} is set, and
> do not send a request after the wait or the retry backoff once force-closing;
> the request is then failed by {{{}TransactionManager#close{}}}. Graceful
> close is unchanged. Two {{SenderTest}} cases reproduce it (they fail without
> the fix).
> This shrinks the window but does not close it: the producer can still be
> force closed right after the check, and a request that is already sent still
> reaches the coordinator. Fully closing it needs a protocol-level change.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)