Uploaded image for project: 'Commons DBCP'
  1. Commons DBCP
  2. DBCP-569

Fix test random failure on TestSynchronizationOrder.testInterposedSynchronization

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.9.0
    • Labels:
      None
    • Flags:
      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

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                fguillaume Florent Guillaume
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m