# Close the connections that were still in the pool
for conn in connections:
+ conn._pool = None
conn.close()
# Signal to eventual clients in the queue that business is closed.
# Check for expired connections
if conn._expire_at <= monotonic():
logger.info("discarding expired connection %s", conn)
+ conn._pool = None
conn.close()
self.run_task(AddConnection(self))
continue
if conn._expire_at <= monotonic():
self.run_task(AddConnection(self))
logger.info("discarding expired connection")
+ conn._pool = None
conn.close()
return
ex,
conn,
)
+ conn._pool = None
conn.close()
elif status == TransactionStatus.ACTIVE:
# Connection returned during an operation. Bad... just close it.
logger.warning("closing returned connection: %s", conn)
+ conn._pool = None
conn.close()
if self._reset:
)
except Exception as ex:
logger.warning(f"error resetting connection: {ex}")
+ conn._pool = None
conn.close()
def _shrink_pool(self) -> None:
nconns_min,
self.max_idle,
)
+ to_close._pool = None
to_close.close()
def _get_measures(self) -> dict[str, int]:
# Close the connections that were still in the pool
for conn in connections:
+ conn._pool = None
await conn.close()
# Signal to eventual clients in the queue that business is closed.
# Check for expired connections
if conn._expire_at <= monotonic():
logger.info("discarding expired connection %s", conn)
+ conn._pool = None
await conn.close()
self.run_task(AddConnection(self))
continue
if conn._expire_at <= monotonic():
self.run_task(AddConnection(self))
logger.info("discarding expired connection")
+ conn._pool = None
await conn.close()
return
ex,
conn,
)
+ conn._pool = None
await conn.close()
elif status == TransactionStatus.ACTIVE:
# Connection returned during an operation. Bad... just close it.
logger.warning("closing returned connection: %s", conn)
+ conn._pool = None
await conn.close()
if self._reset:
)
except Exception as ex:
logger.warning(f"error resetting connection: {ex}")
+ conn._pool = None
await conn.close()
async def _shrink_pool(self) -> None:
nconns_min,
self.max_idle,
)
+ to_close._pool = None
await to_close.close()
def _get_measures(self) -> dict[str, int]:
with pytest.raises(TypeError, match="close_returns=True"):
pool.ConnectionPool(dsn, connection_class=MyConnection, close_returns=True)
+
+
+@pytest.mark.skipif(PSYCOPG_VERSION < (3, 3), reason="psycopg >= 3.3 behaviour")
+def test_close_returns_no_loop(dsn):
+ with pool.ConnectionPool(
+ dsn, min_size=1, close_returns=True, max_lifetime=0.05
+ ) as p:
+ conn = p.getconn()
+ sleep(0.1)
+ assert len(p._pool) == 0
+ sleep(0.1) # wait for the connection to expire
+ conn.close()
+ sleep(0.1)
+ assert len(p._pool) == 1
+ conn = p.getconn()
+ sleep(0.1)
+ assert len(p._pool) == 0
+ conn.close()
+ sleep(0.1)
+ assert len(p._pool) == 1
with pytest.raises(TypeError, match="close_returns=True"):
pool.AsyncConnectionPool(dsn, connection_class=MyConnection, close_returns=True)
+
+
+@pytest.mark.skipif(PSYCOPG_VERSION < (3, 3), reason="psycopg >= 3.3 behaviour")
+async def test_close_returns_no_loop(dsn):
+ async with pool.AsyncConnectionPool(
+ dsn, min_size=1, close_returns=True, max_lifetime=0.05
+ ) as p:
+ conn = await p.getconn()
+ await asleep(0.1)
+ assert len(p._pool) == 0
+ await asleep(0.1) # wait for the connection to expire
+ await conn.close()
+ await asleep(0.1)
+ assert len(p._pool) == 1
+ conn = await p.getconn()
+ await asleep(0.1)
+ assert len(p._pool) == 0
+ await conn.close()
+ await asleep(0.1)
+ assert len(p._pool) == 1