[CONPY-40] connection pool issues Created: 2020-01-27  Updated: 2020-06-18  Resolved: 2020-01-28

Status: Closed
Project: MariaDB Connector/Python
Component/s: Generic
Affects Version/s: 0.9.53
Fix Version/s: 0.9.54

Type: Bug Priority: Critical
Reporter: Wayne Davison (Inactive) Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to CONPY-73 Error from connection pool: No more c... Closed

 Description   

I'm having issues using connection pools. I've only managed to get them to work when the C code allocates the connection, either via creation of the pool object (where the connect options allocates all the available pool slots) or by adding connection options via set_config() and then using add_connection() with no arg. If I try to add a connection I've made in the python code it either fails with an error or I get a segfault. So, to be clear, here's what works and what doesn't:

Works (all connections pre-allocated):

pool = mariadb.ConnectionPool(
    pool_name = 'pool1',
    pool_size = 3,
    host = 'localhost',
    user = 'root',
    database = 'test',
    )

Works (all connections added via internal connection):

pool = mariadb.ConnectionPool(pool_name = 'pool1')
pool.set_config(
        pool_size = 3,
        host = 'localhost',
        user = 'root',
        database = 'test',
        )
for j in range(3):
    pool.add_connection()

Fails with an error on the first add:

pool = mariadb.ConnectionPool(
        pool_name = 'pool1',
        pool_size = 3,
        )
for j in range(3):
    c = mariadb.connect(
        host = 'localhost',
        user = 'root',
        database = 'test',
        )
    pool.add_connection(c)

=> mariadb.PoolError: Couldn't get configuration for pool 'pool1'.

This segfaults on the first add:

pool = mariadb.ConnectionPool(pool_name = 'pool1')
pool.set_config(pool_size = 3)
for j in range(3):
    c = mariadb.connect(
        host = 'localhost',
        user = 'root',
        database = 'test',
        )
    pool.add_connection(c)

Here's one more failure:

def get_a_connection(pool):
    conn = None
    while not conn:
        try:
            conn = pool.get_connection()
            break
        except mariadb.PoolError as e:
            pass
        try:
            pool.add_connection()
        except mariadb.PoolError as e:
            print(f"Pool is full: {e}")
            break
 
    return conn
 
pool = mariadb.ConnectionPool(pool_name = 'pool1')
 
pool.set_config(
    pool_size = 3,
    host = 'localhost',
    user = 'root',
    database = 'test',
    )
for j in range(3):
    conn = get_a_connection(pool)

=> first add_connection() fails with:
=> TypeError: 'sqlstate' is an invalid keyword argument for this function

These tests were done with the latest pip3 install --pre mariadb code using python 3.6.9.



 Comments   
Comment by Georg Richter [ 2020-01-28 ]

The second example works ok, the same behavior when using MySQL Connector/Python:

pool.add_connection(c)
File "/home/georg/.local/lib/python3.8/site-packages/mysql/connector/pooling.py", line 262, in add_connection
raise errors.PoolError(
mysql.connector.errors.PoolError: Connection configuration not available

Comment by Georg Richter [ 2020-01-28 ]

Fixed. rev. 87c4520c5596b7033fa3bba7c24f4433f24d5fa7

Generated at Thu Feb 08 03:29:48 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.