-
Notifications
You must be signed in to change notification settings - Fork 13k
Description
I've been reading the code of DefaultSqlSession and I believe that transactions are not correctly closed when close() is called. The current behaviour is that rollback is submitted only for INSERT/UPDATE/DELETE statements, but not SELECT. Because there is no rollback, the same transaction continues and multiple logical operations may be called in the same transaction, with unpredictable side-effects. For example, a SELECT... FOR UPDATE could create a lock that is not released. Advisory locks wouldn't be released.
The correct behaviour is to ROLLBACK is any one query, including SELECTs.
EDIT The same problem exists with calling close() and rollback(). In our case, we always force commits and rollbacks, but there's no such option for the close operation.
MyBatis version
3.5.7
Database vendor and version
Possibly all, but I have Postgres in mind.
Test case or example project
None.
Steps to reproduce
With connection pooling configured, create a session object, submit some SELECT queries, then close the session without committing or rolling back.
Expected result
Closing SQL session will ROLLBACK the connection.
Actual result
There is no ROLLBACK. EDIT 2022-12-03 Transaction remains active in idle state until the connection is reused. Transaction is committed.