2 Replies Latest reply on Feb 20, 2007 12:22 PM by genman

    Pottential race condition in PoolFiller

    dlofthouse

      I was looking at some of the optimisations in the JCA code and it looks like there is a potential race condition in the PoolFiller implementation, just wanted to check if you wanted a Jira task raising so it can be addressed?

      http://anonsvn.jboss.org/repos/jbossas/branches/Branch_4_2/connector/src/main/org/jboss/resource/connectionmanager/PoolFiller.java

      The class PoolFiller.java uses two seperate synchronized blocks in the run method

       while (true)
       {
       try
       {
       InternalManagedConnectionPool mcp = null;
       //keep iterating through pools till empty, exception escapes.
       while (true)
       {
      
       synchronized (pools)
       {
       mcp = (InternalManagedConnectionPool)pools.removeFirst();
       }
       if (mcp == null)
       break;
      
       mcp.fillToMin();
       }
       }
       catch (Exception e)
       {
       }
      
       try
       {
       synchronized (pools)
       {
       pools.wait();
       }
       }
       catch (InterruptedException ie)
       {
       return;
       }
       }


      It is possible that after the first synchronized block has finished a new connection pool is added to the list of pools before the second block is reached, the second block unconditionally waits and does not check that the list of pools is empty.

      The wait could be wrapped with a call to isEmpty: -
       if (pools.isEmpty())
       {
       pools.wait();
       }


      Or both synchronized blocks could be merged into one.