3 Replies Latest reply on Mar 2, 2004 2:13 PM by joehung

    Connection pool leak if transaction marked for rollback? / 2

    msquance

      Hi,

      I'm experiencing what appears to be a bug in the XADataSource pool when trying to grab a connection in a transaction that has been marked for rollback. It seems to hang onto it within the pool, even though it was not successful in issuing the connection to the caller.

      I am using JBoss 2.4.9 with Oracle 8i.

      In looking at the ObjectPool code, I can see that the getObject() method does not seem to release anything if an exception is thrown after marking the object as in use.

      I haven't found what package ObjectPool belongs to in JBoss 3.0 so I'm not sure if it has been fixed there already.

      Here is some sample code that I reproduced this with. It's a message driven bean getting invoked. After the 50 time in the loop, I get No ManagedConnections Available (my pool size is 50).

      public void onMessage( Message inMessage )
      {
      try {
      UserTransaction userTrans = myContext_.getUserTransaction();
      userTrans.setTransactionTimeout( 1 );

      // start the transaction
      userTrans.begin();

      // wait for the timeout
      Thread.sleep( 1500 );

      InitialContext initCtx = new InitialContext();
      javax.sql.DataSource dataSource =
      (javax.sql.DataSource) initCtx.lookup( "java:ProfilerDS" );

      for ( int i = 0; i < 55; i++ ) {
      try {
      java.sql.Connection con = dataSource.getConnection();

      } catch ( Exception ex ) {
      trace.error( "Caught Exception: " + ex );
      }

      }
      userTrans.rollback();

      } catch ( Exception ex ) {
      trace.error( ex );
      }
      }

      Am I missing something, or is this a bug? I haven't tried enabling the idle timeouts or garbage collection yet, but I'm hoping that might be a workaround to return these objects to the pool.

      Any thoughts would be appreciated.

      Thanks,
      Mike.