"Enlisted connection used without active transaction" during committing transactions with active async threads
See original GitHub issueDescribe the bug
Hi guys! I’ve found out recently that not all of my transactions are committed. The small investigation led me to believe there is a problem in the commit transaction process: when some of the async processing is not finished yet using CompletableStage/CompletableFuture, the transaction fails with the message “Error trying to transactionCommit local transaction: Enlisted connection used without active transaction”. I’ve attached a small reproducer for you with a simple test to check this behavior.
I know it’s better to finish all async execution before committing the transaction. But there are cases when it’s not under developer control. For example, in my project I have code like this:
@Transaction(REQUIRES_NEW)
public Optional<Integer> someMethod() {
CompletableFuture<SomeResponse> timedResponse = new CompletableFuture<>();
try {
timedResponse = restClient.makeRequest().toCompletableFuture();
SomeResponse response = timedResponse.get(TIMEOUT_CONST, MILLISECONDS);
repository.persist(new Entity(response.getId));
return Optional.of(response.getId());
} catch (Exception ex) {
try {
// cancel rest request future if not completed yet
timedResponse.cancel(true);
} catch (Exception ignored) {}
return Optional.empty();
}
}
It’s just some pseudo-code example of how hard it is to control async execution here. And from time to time I receive 500 exception during rest request (that is OK and expected). But the problem is that there are cases when I receive a warning “commiting with 2 threads active!” and right after this exception “Enlisted connection used without active transaction”. Please see the reproducer.
Expected behavior
The transaction is committed with a warning may be but without exception.
Actual behavior
The transaction is not committed with warning and exception “Error trying to transactionCommit local transaction: Enlisted connection used without active transaction”
How to Reproduce?
- Run TransactionCommitTest.test()
- Check that transaction is not committed and there is an exception in logs
Output of uname -a
or ver
No response
Output of java -version
java version “11.0.12” 2021-07-20 LTS
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.6.1.Final
Build tool (ie. output of mvnw --version
or gradlew --version
)
No response
Additional information
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:16 (6 by maintainers)
Top GitHub Comments
Got the same problem, but with the Emitter from smallrye-reactive-messaging-kafka
Same here. I’m emitting some data with
smallrye-reactive-messaging-kafka
then I want to update the DB, but I can’t.I managed to write to the database using the
Event Bus
. And even if my code is working, it throws anyway:javax.transaction.xa.XAException: Error trying to transactionCommit local transaction: Enlisted connection used without active transaction
Here is some example code…