[ 
https://issues.apache.org/jira/browse/QPID-6534?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Rudyy updated QPID-6534:
-----------------------------
    Status: Open  (was: Reviewable)

Rob,
Current implementation of PooledConnectionFactory can leak connections when 
maxPoolSize is exceeded. The exceeding connections are not got returned into 
pool on calling their 'close' method and their underlying connection is not 
called either.

The following system test demonstrates the issue:
{code}
public class PooledConnectionFactoryTest extends QpidRestTestCase
{
    public void testConnectionLeakAfterReachingMaximumPoolSize() throws 
Exception
    {
        PooledConnectionFactory factory = new PooledConnectionFactory();
        factory.setMaxPoolSize(2);

        String url = "amqp://" + GUEST_USERNAME + ":" + GUEST_PASSWORD + 
"@clientid/test?brokerlist='" + getBroker() + "?retries='0''";
        factory.setConnectionURLString(url);

        Connection connection1 = factory.createConnection();
        Connection connection2 = factory.createConnection();
        Connection connection3 = factory.createConnection();
        Connection connection4 = factory.createConnection();

        connection1.close();
        connection2.close();
        connection3.close();
        connection4.close();

        List<Map<String,Object>> allConnections = 
getRestTestHelper().getJsonAsList("connection/*");
        assertEquals("PolledConnectionFactory is leaking connections", 2, 
allConnections.size());
    }
}
{code}

It seems that fix for the issue would be to close the underlying connection in 
returnToPool method when connection is not returned into pool
{code}
@@ -308,13 +308,18 @@ public class PooledConnectionFactory implements 
ConnectionFactory, QueueConnecti
                     scheduleReaper();
                 }
             }
+            boolean returned = false;
             synchronized (connections)
             {
                 if(connections.size()<_maxPoolSize.get())
                 {
-                    connections.add(new ConnectionHolder(connection, 
System.currentTimeMillis()));
+                    returned = connections.add(new 
ConnectionHolder(connection, System.currentTimeMillis()));
                 }
             }
+            if (!returned)
+            {
+                connection.close();
+            }
         }
     }

{code}

> [Java Client] Add a pooled connection factory
> ---------------------------------------------
>
>                 Key: QPID-6534
>                 URL: https://issues.apache.org/jira/browse/QPID-6534
>             Project: Qpid
>          Issue Type: Improvement
>            Reporter: Rob Godfrey
>            Assignee: Rob Godfrey
>             Fix For: 6.0 [Java]
>
>
> When interacting with frameworks it is often the case that connections are 
> created, used and then closed frequently.  Creating a connection has a high 
> overhead and thus it would be advantageous to provide a connection factory 
> which can pool connections that can be reused.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to