2 Replies Latest reply on Jan 16, 2004 2:38 PM by adrian.brock

    Bug in InternalManagedConnectionPool (permits)

       

      "jbossuser" wrote:
      "jbossuser" wrote:
      Not sure if I found a bug, but it looks like one from a code read.

      Basically, what I think I found is that when a getConnection is called, a permit is reserved (permits.attempt). However, if the connection went bad, it is destroyed (for example if it matchManagedConnections returns null without an exception.

      The problem is, I can't find when the permit would be released in this case. If this happened enough times, you'd run out of permits (I think).



        • 1. Re: Bug in InternalManagedConnectionPool (permits)

           

          "jbossuser" wrote:
          "jbossuser" wrote:
          Never mind...found the logic.


          • 2. Re: Bug in InternalManagedConnectionPool (permits)

             

            "adrian@jboss.org" wrote:
            "adrian@jboss.org" wrote:
            Reread the code.

            It's basic format is

            public Connection getConnection()
            {
            if (permits.attempt())
            {
             if (canMatchAConnectionInPool)
             return thatConnection;
             try
             {
             return createNewConnection();
             }
             catch (Throwable t)
             {
             permits.release();
             }
            }
            throw ResourceException;
            }
            
            public void returnConnection()
            {
             putConnectionBackInPool();
             permits.release();
            }
            


            As you can see if there is no match in the pool, it creates a new connection.
            If that fails, the permit is released and an error is thrown.

            Once the connection is out of the pool, the only way to release the permit
            is to return the connection to the pool.

            Regards,
            Adrian