You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Florent Guillaume (Jira)" <ji...@apache.org> on 2021/01/04 00:45:00 UTC

[jira] [Created] (DBCP-569) Fix test random failure on TestSynchronizationOrder.testInterposedSynchronization

Florent Guillaume created DBCP-569:
--------------------------------------

             Summary: Fix test random failure on TestSynchronizationOrder.testInterposedSynchronization
                 Key: DBCP-569
                 URL: https://issues.apache.org/jira/browse/DBCP-569
             Project: Commons DBCP
          Issue Type: Bug
            Reporter: Florent Guillaume


{{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:
{noformat}
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)
{noformat}


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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)