-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Affects Version(s):
2.9.0 (an earlier - starting 2.5.17, 2.6.12, 2.7.9 and 2.8.0)
We are using transaction synchronization mechanism for scheduling some business logic beforeCommit, afterCommit etc. (hibernate transaction), in this logic we sometimes are sending transactional kafka messages
Everything was working fine with kafka 2.7.1 + spring-kafka 2.7.6 (Spring boot 2.5.4)
After upgrading to kafka 3.2.0 + spring-kafka 2.9.0 we started to receive errors:
beginTransaction failed: CloseSafeProducer [delegate=org.apache.kafka.clients.producer.KafkaProducer@238e30ae]
java.lang.IllegalStateException: TransactionalId tx-fsm-core-jIAGrMnP58-0: Invalid transition attempted from state IN_TRANSACTION to state IN_TRANSACTION
I believe, problem was introduced in #2005 - in ProducerFactoryUtils commit on resourceHolder was moved from afterCompletion method to processResourceAfterCommit method.
Problem now is, that in TransactionSynchronization.afterCommit() kafka transaction is being attached to main transaction (hibernate) which is still active, but already commited, and because of that it is not being commited afterwards (main transaction afterCommit method was already fired, and resourceHolder commit method will not be executed)
Problem exist only when sending kafka messages in afterCommit.
beforeCommit, and synchronous processing (without transaction synchronization) is working fine.
To Reproduce
Explained above
Expected behavior
Kafka transaction properly commited when invoked in other transaction synchronization afterCommit method.
Sample