Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
Patch
Description
TestSynchronizationOrder.testInterposedSynchronization may fail randomly depending on GC behavior, because the test involves a Transaction object held only be weak references, which may be cleared earlier that the test expects:
java.sql.SQLException: Unable to enlist connection because the transaction has been garbage collected at org.apache.commons.dbcp2.managed.TransactionContext.getTransaction(TransactionContext.java:186) at org.apache.commons.dbcp2.managed.TransactionContext.setSharedConnection(TransactionContext.java:105) at org.apache.commons.dbcp2.managed.ManagedConnection.updateTransactionStatus(ManagedConnection.java:310) at org.apache.commons.dbcp2.managed.ManagedConnection.<init>(ManagedConnection.java:89) at org.apache.commons.dbcp2.managed.ManagedDataSource.getConnection(ManagedDataSource.java:64) at org.apache.commons.dbcp2.managed.TestSynchronizationOrder.testInterposedSynchronization(TestSynchronizationOrder.java:118)
The TransactionContext.transactionRef and the TransactionRegistry.caches are holding onto the Transaction (acquired in TransactionRegistry.getActiveTransactionContext()) only using weak refs.
However in TestSynchronizationOrder the fake TransactionManager returns a Transaction (that's an instance of an anonymous class) but nobody holds a strong reference to that. The fake TransactionManager should create the fake Transaction at begin() time, and hold onto it using a strong reference until commit() time.
Attachments
Issue Links
- links to