Skip to content

Conversation

garyrussell
Copy link
Contributor

Resolves #2604

Prior to #2005 synchronized transactions were committed in afterCompletion. This was incorrect because a failure to commit was not propagated to the caller. However, if a higher order synchronization throws an exception in afterCommit, the producer is closed (returned to the cache) while still in a transaction - the transaction was not committed.

Restore the commit in afterCompletion and add a check in KafkaResourceHolder to only commit once.

Add tests.

cherry-pick to 2.9.x

Resolves spring-projects#2604

Prior to spring-projects#2005 synchronized transactions were committed in `afterCompletion`.
This was incorrect because a failure to commit was not propagated to the caller.
However, if a higher order synchronization throws an exception in `afterCommit`,
the producer is closed (returned to the cache) while still in a transaction -
the transaction was not committed.

Restore the commit in `afterCompletion` and add a check in `KafkaResourceHolder`
to only commit once.

Add tests.

**cherry-pick to 2.9.x**
@artembilan artembilan merged commit 1278a9c into spring-projects:main Mar 2, 2023
artembilan pushed a commit that referenced this pull request Mar 2, 2023
Resolves #2604

Prior to #2005 synchronized transactions were committed in `afterCompletion`.
This was incorrect because a failure to commit was not propagated to the caller.
However, if a higher order synchronization throws an exception in `afterCommit`,
the producer is closed (returned to the cache) while still in a transaction -
the transaction was not committed.

Restore the commit in `afterCompletion` and add a check in `KafkaResourceHolder`
to only commit once.

Add tests.

**cherry-pick to 2.9.x**
@garyrussell garyrussell deleted the GH-2604 branch March 2, 2023 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Synchronized kafka transaction is not commited nor rolled back when code from custom "afterCommit" throws exception
2 participants