Bug #121930 Connector/J 9.7.0 skips rollback after SELECT result-reading timeout with useLocalTransactionState=true
Description:
With Connector/J 9.7.0 and useLocalTransactionState=true, a SELECT timeout while the driver is reading result rows (error 3024, SQLSTATE HY000) can cause Connection.rollback() to return normally without rolling back preceding writes. A subsequent INSERT and commit() on the same connection commits both the original and new writes, verified through a separate connection. We reproduced this using standalone JDBC against Percona Server for MySQL 8.0.33-25 without a connection pool. Changing only useLocalTransactionState to false restored correct rollback behavior.
How to repeat:
We observed this with standalone JDBC using Connector/J 9.7.0 and Percona Server for MySQL 8.0.33, without a connection pool.
1. Open a connection with useLocalTransactionState=true and auto commit set to false
2. Do an INSERT, leave it uncommitted
3. Execute a SELECT that begins returning rows, then times out while Connector/J is reading the result, producing error 3024, SQLSTATE HY000
- We used a 150 ms execution timeout and a query that returns many rows, with SLEEP applied to later rows. With buffered results, the exception can occur inside executeQuery().
4. Call connection.rollback(), it returns successfully
5. On the same connection, do another INSERT
6. Call connection.commit()
7. From a separate connection, read the data that was written
It should be that only the second INSERT is actually committed, but what we found when useLocalTransactionState was true is that both INSERTS were present. Repeating the test with only useLocalTransactionState changed to false yielded the correct behavior.
Suggested fix:
Ensure errors while reading query results do not incorrectly clear the cached transaction-active state. With useLocalTransactionState=true, Connection.rollback() should skip the server round trip only when the driver reliably knows no transaction is active. If transaction state is uncertain, send ROLLBACK and wait for the server’s successful response. If rollback cannot complete, propagate the failure instead of returning normally.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.038 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.