Skip to content

Commit

Permalink
Do not automatically rollback XA connections
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Jan 7, 2025
1 parent 569d0cf commit 44fd4b3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docs/src/main/asciidoc/datasource.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ Oracle has a very weird behavior of committing the uncommitted transactions on c

Which means that when stopping Quarkus for instance, in progress transactions might be committed even if incomplete.

Given that is not the expected behavior and that it could lead to data loss, we added an interceptor that rolls back any unfinished transactions at connection close.
Given that is not the expected behavior and that it could lead to data loss, we added an interceptor that rolls back any unfinished transactions at connection close,
provided you are not using XA (in which case the transaction manager handles things for you).

If this behavior introduced in 3.18 causes issues for your specific workload, you can disable it by setting the `-Dquarkus-oracle-no-automatic-rollback-on-connection-close` system property to `true`.
Please take the time to report your use case in our https://github.com/quarkusio/quarkus/issues[issue tracker] so that we can adjust this behavior if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.jboss.logging.Logger;

import io.agroal.api.AgroalPoolInterceptor;
import io.agroal.pool.wrapper.ConnectionWrapper;
import oracle.jdbc.OracleConnection;

/**
Expand Down Expand Up @@ -38,6 +39,13 @@ public void onConnectionDestroy(Connection connection) {
return;
}

// do not rollback XA connections, they are handled by the transaction manager
if (connection instanceof ConnectionWrapper connectionWrapper) {
if (connectionWrapper.getHandler().getXaResource() != null) {
return;
}
}

try {
if (connection.unwrap(Connection.class) instanceof OracleConnection oracleConnection) {
if (connection.isClosed() || connection.getAutoCommit()) {
Expand All @@ -50,4 +58,4 @@ public void onConnectionDestroy(Connection connection) {
LOG.trace("Ignoring exception during rollback on connection close", e);
}
}
}
}

0 comments on commit 44fd4b3

Please sign in to comment.