Bug 64570 - Transaction not rollbacked if autocommit is false
Summary: Transaction not rollbacked if autocommit is false
Status: NEW
Alias: None
Product: Tomcat Modules
Classification: Unclassified
Component: jdbc-pool (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2020-07-01 06:47 UTC by Ronald
Modified: 2020-07-01 06:47 UTC (History)
0 users

Packet capturing using wireshark (403.95 KB, application/gzip)
2020-07-01 06:47 UTC, Ronald

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald 2020-07-01 06:47:17 UTC
Created attachment 37344 [details]
Packet capturing using wireshark

I think I found a bug in the Tomcat JDBC Pool.

If I start a connection with autoCommit set to false and default autoCommit is set to true, the active transaction is not rollbacked when the connection is closed.

I think the bug is located in the terminateTransaction method in the ConnectionPool class: if one sets the autoCommit manually to false and afterwards the connection is closed without committing or rollback, the transaction stays open.

See line 888 of ConnectionPool. 

Code to reproduce:

conn = dataSource.getConnection();
ps = conn.prepareStatement(sqlStatement, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
rs = ps.executeQuery();
while(rs.next()) {
 // do something with result

=> Postgres connection stays in state: Ready for query (in a transaction)

All other connection pools rollback active transaction on close of connection.

See wireshark capture:
Correct behaviour: packet 2698 -> 2701 (same for commons-dbcp, hikari and c3p0)
Incorrect behaviour: packet 12018 -> missing rollback