Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deffered setAutoCommit call leads to idle in transaction sessions in PostgreSQL #734

Open
radist-nt opened this issue Aug 11, 2021 · 1 comment

Comments

@radist-nt
Copy link

radist-nt commented Aug 11, 2021

We have issues with idle in transaction sessions in PostgreSQL database initiated from datasource configured in Wildfly 18.0.0.Final. The last query differs from one connection to another (and sometimes the last query is internal query issued by PostgreSQL JDBC driver). Long transactions and hanging idle in transaction sessions are a potential problem, as said at almost every PostgreSQL-related event.
We found that our code calls connection.setAutoCommit(true); before returning connection to pool with connection.close();. On the another side, the setAutoCommit method from PostgreSQL JDBC driver makes the commit (which will actually rollback in the case of failed transaction) if the transaction is active (idle in transaction state).
Further investigation leads to the deffered setAutoCommit call in the {{org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection}} class and issue JBJCA-1338 with PR #602 which was merged and then reverted due to JBEAP-9730. So then another fix has been provided in PR #623, but it fixed only JBJCA-1338, but not the more serious problem: the underlined jdbc connection is left at the unexpected autoCommit state during the unpredictable time of waiting in pool.

According to the analisys in this message, the test in JBEAP-9730 was failed due to commit command in postgresql jdbc driver. But actually, commit command always leads to rollback in PostgreSQL, so it's unlikely a real problem.
I have not found the failing test sources, so cannot find how they detected the commit called from database driver (by mocking the jdbc driver internal classes?), so cannot decide how to make fix in cleanup method. But why not to add the mc.checkTransaction(); call into the org.jboss.jca.adapters.jdbc.WrappedConnection.close() method to set the underlying connection to the expected state before returning connection to pool?

Currently the workaround is to call any method which calls org.jboss.jca.adapters.jdbc.WrappedConnection.checkTransaction() internally before closing connection, but it looks like a dirty hack.

@tadamski
Copy link
Contributor

tadamski commented Aug 17, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants