Bugs item #846551, was opened at 2003-11-21 12:45
Message generated for change (Comment added) made by ejort
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=846551&group_id=22866

Category: JBossCX
Group: v3.2
>Status: Closed
>Resolution: Out of Date
Priority: 5
Submitted By: Walter McConnell (waltermcconnell)
Assigned to: Adrian Brock (ejort)
Summary: expn in getConneciton makes pool count wrong

Initial Comment:
Red Hat  9  (2.4.20-6)
JDK 1.4.1_02

When a ResourceException is thrown from within the
getConnection method of a ManagedConnection, the pool
count becomes wrong. This happens because while a
permit is accepted in
InternalManagedConnecitonPool.getConnection() it is
never released in the case of an error.
BaseConnectionManager2 will never call returnConnection
on the connection manager in the case that
ManagedConnection.getConnecion() fails .. 

its easy to reproduce .. just add this unit test to
BaseConnectionManagerUnitTestCase ... in order to get
the test to fail you will need to temporarily get the
TestManagedConnection to throw an exception in its
getConnecion method .. 

 public void
testExceptionInGetConnectionLeavesPoolCountWrong()
throws Exception
   {
      InternalManagedConnectionPool.PoolParams pp = new
InternalManagedConnectionPool.PoolParams();
      pp.minSize = 0;
      pp.maxSize = 5;
      pp.blockingTimeout = 100;
      pp.idleTimeout = 500;
                                                      
                                                      
                                
      ManagedConnectionFactory mcf = new
TestManagedConnectionFactory();
      ManagedConnectionPool poolingStrategy = new
JBossManagedConnectionPool.OnePool(mcf, pp, log);
      BaseConnectionManager2 cm = new
NoTxConnectionManager(ccm, poolingStrategy);
                                                      
                                                      
                                
      try{
      Object mc = cm.allocateConnection(mcf, null);
      } catch(Exception thrown) {
        System.err.println("Caught Exception " +
thrown.toString());
      }
                                                      
                                                      
                                
      assertTrue("Wrong number of connections counted:
" + cm.getConnectionCount(), cm.getConnectionCount() == 0);
   }


the fix seems pretty trivial too ... In
BaseConnectionManager2.allocateConnection() [line 473],
just wrap the call to mc.getConnection() with a
try/catch .. if it throws a ResoruceException then tell
the pooling strategy to return the connection, killing
it. Then re-throw the exception. 

BaseConnectionManager2.java [Line 491 ....]

     try 
        {
        Object connection = mc.getConnection(subject, cri);
        registerAssociation(mc, connection);
        if (ccm != null)
          {
            ccm.registerConnection(this, new
ConnectionRecord(mc, connection, cri));
          } // end of if ()
        return connection;
        } catch(ResourceException thrown) 
            {
         poolingStrategy.returnConnection(mc, true);
         throw thrown;
       }

I've also attached a test rar and a web app that will
show the problem in a running JBoss server .. after
deploying the lot into the deploy directory, then keep
an eye on the "AvailableConnectionCount" in the
ManagedConnectionPools MBean view  .. you will see it
dropping towards 0 as you refresh the
http://localhost:8080/testwar page .. this is obviously
incorrect as when it hits 0, the pool will refuse
connections and the JBoss pool manager will blow .. 

cheers, 
Walter McConnell.
IONA Technologies.

----------------------------------------------------------------------

>Comment By: Adrian Brock (ejort)
Date: 2003-11-26 08:51

Message:
Logged In: YES 
user_id=9459

The code you are referring to is not the current version.
It looks like jboss-3.2.1

There was a lot of tidying up of the connection manager/pool
in 3.2.2 to fix the error handling.

If you look at the pool in 3.2.2 you'll see it catches the
ResourceException itself.
There are now tests in the testsuite for exceptions (both
resource exceptions and untrapped throwables).

It was also switched to a more stateless design to avoid
concurrency problems.

Regards,
Adrian

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=376685&aid=846551&group_id=22866


-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive?  Does it
help you create better code?  SHARE THE LOVE, and help us help
YOU!  Click Here: http://sourceforge.net/donate/
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to