This project is archived and is in readonly mode.
minconn and maxconn in pool code allow for non integer values resulting in unbounded pool
Reported by Psycopg website | June 13th, 2014 @ 03:47 PM
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.
Comments and changes to this ticket
-
Daniele Varrazzo August 13th, 2014 @ 01:35 AM
- State changed from new to resolved
Fixed in psycopg 2.5.4. The class init now attempts a conversion to int.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.