You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2020/07/01 06:47:17 UTC

[Bug 64570] New: Transaction not rollbacked if autocommit is false

https://bz.apache.org/bugzilla/show_bug.cgi?id=64570

            Bug ID: 64570
           Summary: Transaction not rollbacked if autocommit is false
           Product: Tomcat Modules
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: jdbc-pool
          Assignee: dev@tomcat.apache.org
          Reporter: ronald.dehuysser@gmail.com
  Target Milestone: ---

Created attachment 37344
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=37344&action=edit
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();
conn.setAutoCommit(false);
ps = conn.prepareStatement(sqlStatement, ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY);
ps.setFetchSize(100);
paramsSetter.accept(ps);
rs = ps.executeQuery();
while(rs.next()) {
 // do something with result
}
rs.close()
ps.close()
conn.close()


=> 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

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 64570] Transaction not rollbacked if autocommit is false

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64570

--- Comment #1 from Christopher Schultz <ch...@christopherschultz.net> ---
(In reply to Ronald from comment #0)
> 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();
> conn.setAutoCommit(false);
> ps = conn.prepareStatement(sqlStatement, ResultSet.TYPE_FORWARD_ONLY,
> ResultSet.CONCUR_READ_ONLY);
> ps.setFetchSize(100);
> paramsSetter.accept(ps);
> rs = ps.executeQuery();
> while(rs.next()) {
>  // do something with result
> }
> rs.close()
> ps.close()
> conn.close()
> 
> 
> => 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

What happens if you check the connection back out of the pool after it's been
returned (the first time)? Does your transaction get rolled-back or committed?

I think it's a matter of taste as to whether or not a rollback() should be
performed when returning the connection to the pool. If the application is
working properly, then a rollback is a wasted command to the database.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 64570] Transaction not rollbacked if autocommit is false

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64570

--- Comment #2 from Konstantin Kolinko <kn...@gmail.com> ---
https://tomcat.apache.org/tomcat-11.0-doc/jdbc-pool.html

See "rollbackOnReturn" attribute. It is false by default.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 64570] Transaction not rollbacked if autocommit is false

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=64570

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #3 from Mark Thomas <ma...@apache.org> ---
Closing based on comment #2

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org