Submitted by: bhazuka@usgs.gov
While working with connection pools the
AbstractConnectionPool(minconn, maxconn, args, **kwargs),
SimpleConnectionPool(minconn, maxconn, *args, **kwargs) and
ThreadedConnectionPool(minconn, maxconn, *args, *kwargs)
classes were ignoring the maxconn value that was being set.
A typical object initialization looked like the following.
pool = SimpleConnectionPool(5,
cfg['database.max_connections'], host=cfg['database.host'],
port=cfg['database.port'], database=cfg['database.db'], user=user,
password=passwd )
Where cfg[] was a dictionary object resulting from the
ConfigParser making all the values configurable. This resulted in
all of the cfg values being of a string type.
Based on the current comparison in the AbstractConnectionPool
code where length of the array must be less than the max connection
an integer gets compared with in the case detailed above a string.
This results in the maxpool size code always resulting in
generating another connection and not limiting the pool size. A
simple fix of int(cfg['database.max_connections']) was able to
resolve the issue once I understood what was going on. I propose
adding a type check in the AbstractConnectionPool class for the
maxconn and minconn variables and raising an error if they are not
type integer.