-
I am experiencing the scenario where the max_lifetime on a connection pool has been exceeded by one of the connections i.e. a simple example here where the max lifetime is set to 15 seconds and the pool size set to 1: database_connection_pool = AsyncConnectionPool(
conninfo=os.environ["DATABASE_URL"],
min_size=1,
max_size=1,
max_lifetime=15.0,
open=False,
kwargs=connection_kwargs) I compile the graph like so: async def get_ai_assistant() -> CompiledStateGraph:
async with database_connection_pool.connection() as conn:
saver = AsyncPostgresSaver(conn)
graph = builder.compile(checkpointer=saver)
return graph When this lifetime has been exceeded I receive a connection closed error. I can see from the psycopg logs that the connection is discarded when returned back to the pool and a new one is added. If I then do the same operation again I get a response back from the graph. Of course, once the 15 seconds have elapsed a second time I get the connection closed error again. The strange thing is, if I simply query the database via a cursor in psycopg then even after the max_lifetime has surpassed it will still work, it's as though the psycopg code is checking the state of the connection and prior to using it and if closed then returning it to the pool and pulling a new one: async def query_database() -> int:
async with database_connection_pool.connection() as conn:
print("connection acquired")
async with conn.cursor() as cur:
print("cursor acquired")
await cur.execute('SELECT COUNT(*) FROM public."checkpoints"')
print("query executed")
result = await cur.fetchone()
print("result fetched")
if result is None:
return 0
else:
count = result["count"]
return count The output of the logs is as follows: I never get any connection closed errors when simply using the cursor. I have tried calling check() on the connection pool but get errors when I do so: async def get_ai_assistant() -> CompiledStateGraph:
await database_connection_pool.check()
async with database_connection_pool.connection() as conn:
saver = AsyncPostgresSaver(conn)
graph = builder.compile(checkpointer=saver)
return graph |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
@GaryFail the problem is here: async with database_connection_pool.connection() as conn:
saver = AsyncPostgresSaver(conn)
graph = builder.compile(checkpointer=saver)
return graph as soon as you leave the in the meantime, we'll be adding proper support to just passing connection pool directly to |
Beta Was this translation helpful? Give feedback.
-
same problem with 1.0.8 |
Beta Was this translation helpful? Give feedback.
@GaryFail we just released
langgraph-checkpoint-postgres==1.0.4
which supports passing connection pool to the postgres saver -- could you try it and see if it resolves your issues?