qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alex Rudyy (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (QPID-6534) [Java Client] Add a pooled connection factory
Date Fri, 22 May 2015 14:19:17 GMT

     [ 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: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


Mime
View raw message