minconn and maxconn in pool code allow for non integer values resulting in unbounded pool #220

Closed
psycoteam opened this Issue Jun 13, 2014 · 1 comment

Projects

None yet

2 participants

@psycoteam

Originally 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.

@dvarrazzo
Member

Fixed in psycopg 2.5.4. The class init now attempts a conversion to int.

@gencer gencer pushed a commit to gencer/psycopg2 that referenced this issue Oct 24, 2014
@dvarrazzo dvarrazzo 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.
41a083c
@gencer gencer pushed a commit to gencer/psycopg2 that referenced this issue Aug 22, 2016
@dvarrazzo dvarrazzo 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.
d232f25
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment