Connections leak with resulting timeout error at the connection get. I am using connection pool configured as follows:
from psycopg_pool import ConnectionPool
pool = ConnectionPool(conninfo=config['postgres']['url'])
@atexit.register
def pool_close():
pool.close()
Then I use the pool's connections to query like this:
def load_smth(...):
with pool.getconn() as conn:
with conn.cursor() as cur:
cur.execute("select cfg from ...",(..))
return smth
The problem is that at 5th request the connection pool doesn't return a connection and my app fails with a connection pool timeout error:
psycopg_pool.PoolTimeout: couldn't get a connection after 30.0 sec
SQL queries are OK, tested with the PostgreSQL server. Moreover, if I reorder queries, failed query works. So it's a problem of getting a connection from the pool.
upd
After some research I tried to use a wrapper to commit after each call, in the following way:
def run_cursor(sql, params=(), callback=lambda x: x):
with pool.getconn() as conn:
with conn.cursor() as cur:
res = callback(cur.execute(sql, params))
conn.commit()
cur.close()
return res
But connections are still leaking out from the pool.