``psycopg_pool`` release notes
==============================
+Future releases
+---------------
+
+psycopg_pool 3.1.8 (unreleased)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Enforce connections' ``max_lifetime`` on `~ConnectionPool.check()`
+ (:ticket:`#482`).
+
+
Current release
---------------
while conns:
conn = conns.pop()
+
+ # Check for expired connections
+ if conn._expire_at <= monotonic():
+ logger.info("discarding expired connection %s", conn)
+ conn.close()
+ self.run_task(AddConnection(self))
+ continue
+
+ # Check for broken connections
try:
conn.execute("SELECT 1")
if conn.pgconn.transaction_status == TransactionStatus.INTRANS:
while conns:
conn = conns.pop()
+
+ # Check for expired connections
+ if conn._expire_at <= monotonic():
+ logger.info("discarding expired connection %s", conn)
+ await conn.close()
+ self.run_task(AddConnection(self))
+ continue
+
+ # Check for broken connections
try:
await conn.execute("SELECT 1")
if conn.pgconn.transaction_status == TransactionStatus.INTRANS:
assert conn.info.transaction_status == TransactionStatus.IDLE
+@pytest.mark.slow
+def test_check_max_lifetime(dsn):
+ with pool.ConnectionPool(dsn, min_size=1, max_lifetime=0.2) as p:
+ with p.connection() as conn:
+ pid = conn.info.backend_pid
+ with p.connection() as conn:
+ assert conn.info.backend_pid == pid
+ sleep(0.3)
+ p.check()
+ with p.connection() as conn:
+ assert conn.info.backend_pid != pid
+
+
@pytest.mark.slow
@pytest.mark.timing
def test_stats_measures(dsn):
assert conn.info.transaction_status == TransactionStatus.IDLE
+@pytest.mark.slow
+async def test_check_max_lifetime(dsn):
+ async with pool.AsyncConnectionPool(dsn, min_size=1, max_lifetime=0.2) as p:
+ async with p.connection() as conn:
+ pid = conn.info.backend_pid
+ async with p.connection() as conn:
+ assert conn.info.backend_pid == pid
+ await asyncio.sleep(0.3)
+ await p.check()
+ async with p.connection() as conn:
+ assert conn.info.backend_pid != pid
+
+
@pytest.mark.slow
@pytest.mark.timing
async def test_stats_measures(dsn):