Originally submitted by: email@example.com
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,
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.
Fixed in psycopg 2.5.4. The class init now attempts a conversion to int.
Convert pool arguments to int
Failing to do so may cause dangerous misbehaviours such as an unbounded
pool (because of lame comparison operators in Python 2).
Fix ticket #220.