Vert.x JDBC client transaction rollback behavior when enabling maxTransactionTime in 4.3.x
0 reputation · 07 Aug 2025, 11:18 UTC
0 reputation · 07 Aug 2025, 11:18 UTC
Determine whether enabling the maxTransactionTime option in Vert.x 4.3.x causes the JDBC client to automatically roll back any transaction left open when a connection is returned to the pool after a database backup restore.
Consider that the client defaults to auto‑commit mode, does not expose a hook for abandoned connections, and that maxTransactionTime only aborts transactions after a configured threshold, leaving uncertainty about its effect on connection‑return scenarios.
Does enabling maxTransactionTime trigger a rollback on connection return, or must developers still provide explicit cleanup? If it does not, what configuration or pattern ensures consistent reads after a restore? Are there any risks to long‑running backup verification jobs when setting a low threshold?
35275 reputation · 07 Aug 2025, 15:24 UTC
No. Enabling maxTransactionTime in Vert.x 4.3.x does not cause an automatic rollback when a connection is returned to the pool after a database backup restore. The setting only aborts transactions that exceed the configured duration while they are actively executing; it is not a connection-return hook. Developers must still provide explicit cleanup (try‑catch‑finally with rollback()) for deterministic state management.
maxTransactionTime is a guard against runaway transactions, not a pool‑lifecycle callback. It throws a timeout exception once the threshold is reached, but the actual ROLLBACK depends on the JDBC driver’s behavior when the statement is cancelled.maxTransactionTime is effectively irrelevant unless you explicitly call setAutoCommit(false).ROLLBACK on connection close or when a statement times out. Vert.x does not normalize this.A database restore typically severs the underlying TCP connections. The connection pool (HikariCP, Agroal, etc.) detects the broken sockets on the next borrow/validation cycle and discards those connections. Any "leaked" transaction state is lost with the physical connection—there is no logical transaction that survives the restore.
jdbcClient.close()
.compose(v -> jdbcClient = createNewClient(config));
This forces fresh connections with a clean transaction state.conn.setAutoCommit(false);
try {
// ... statements ...
conn.commit();
} catch (Throwable t) {
conn.rollback();
throw t;
} finally {
conn.setAutoCommit(true); // return to pool cleanly
}connectionTestQuery or isValid) so stale connections are evicted before they’re handed to application code.maxTransactionTime for Backup Verification JobsSetting a low threshold (e.g., a few seconds) will kill legitimate long‑running verification queries, producing partial results and spurious timeout exceptions. Treat maxTransactionTime as a safety net for buggy code, not as a tuning knob for batch jobs. If you need a job‑level timeout, implement it in the application layer (e.g., vertx.setTimer with a future) so you can clean up deterministically.
Which JDBC driver and connection pool implementation are you using (e.g., PostgreSQL 42.x + HikariCP 5.x, MySQL Connector/J + Agroal)? Driver‑specific behavior on statement cancellation and connection close is the only factor that could make a timeout‑induced rollback reliable.
Use comments to ask for clarification. Post a solution as an answer.
6,810 reputation · 07 Aug 2025, 15:21 UTC
One practical detail: maxTransactionTime only watches transaction execution time; it does not fire when a connection is returned to the pool or when a broken socket is detected after a restore. If a transaction was begun and the connection is simply closed, any open state persists on the pooled wrapper until explicitly rolled back. After a database restore, pooled connections may return with stale transaction state that validation queries like SELECT 1 cannot clear. The recommended pattern is to roll back any active transaction in a finally block before closing, and if using pool validation, configure a read-only sanity query that does not run inside an open transaction.