Don't share connection pool between driver object

Each driver instance must use it's own connection pool.

This removes the last global state of qpid and rabbitmq driver
Make the relation between classes more simple.

The previous behavior was not very safe, as explained in the bug report.

And also, this is a first step to replace this custom connection pool
handling by the kombu one.

Closes bug: #1397925
Partial bug: #1397339

Change-Id: Iecd2b39c76417d9ac081d46810f72eb6e38edfda
This commit is contained in:
Mehdi Abaakouk 2014-12-01 11:11:05 +01:00
parent f2234d291f
commit f3370da11a
3 changed files with 2 additions and 25 deletions

View File

@ -25,7 +25,6 @@ uses AMQP, but is deprecated and predates this code.
import collections
import logging
import threading
import uuid
import six
@ -71,28 +70,6 @@ class ConnectionPool(pool.Pool):
def empty(self):
for item in self.iter_free():
item.close()
# Force a new connection pool to be created.
# Note that this was added due to failing unit test cases. The issue
# is the above "while loop" gets all the cached connections from the
# pool and closes them, but never returns them to the pool, a pool
# leak. The unit tests hang waiting for an item to be returned to the
# pool. The unit tests get here via the tearDown() method. In the run
# time code, it gets here via cleanup() and only appears in service.py
# just before doing a sys.exit(), so cleanup() only happens once and
# the leakage is not a problem.
del self.connection_cls.pools[self.url]
_pool_create_sem = threading.Lock()
def get_connection_pool(conf, url, connection_cls):
with _pool_create_sem:
# Make sure only one thread tries to create the connection pool.
if url not in connection_cls.pools:
connection_cls.pools[url] = ConnectionPool(conf, url,
connection_cls)
return connection_cls.pools[url]
class ConnectionContext(rpc_common.Connection):

View File

@ -723,7 +723,7 @@ class QpidDriver(amqpdriver.AMQPDriverBase):
conf.register_opts(qpid_opts)
conf.register_opts(rpc_amqp.amqp_opts)
connection_pool = rpc_amqp.get_connection_pool(conf, url, Connection)
connection_pool = rpc_amqp.ConnectionPool(conf, url, Connection)
super(QpidDriver, self).__init__(conf, url,
connection_pool,

View File

@ -749,7 +749,7 @@ class RabbitDriver(amqpdriver.AMQPDriverBase):
conf.register_opts(rabbit_opts)
conf.register_opts(rpc_amqp.amqp_opts)
connection_pool = rpc_amqp.get_connection_pool(conf, url, Connection)
connection_pool = rpc_amqp.ConnectionPool(conf, url, Connection)
super(RabbitDriver, self).__init__(conf, url,
connection_pool,