chore: Omit lock when using connection pool (#6734)

Co-authored-by: Conrad Ludgate <conradludgate@gmail.com>
This commit is contained in:
William FH
2026-01-31 00:30:34 +00:00
committed by GitHub
co-authored by Conrad Ludgate
parent c94e7b96ac
commit 193e128c20
5 changed files with 12 additions and 7 deletions
@@ -550,6 +550,11 @@ class AsyncPostgresStore(AsyncBatchedBaseStore, BasePostgresStore[_ainternal.Con
Will be applied regardless of whether the PostgresStore instance was initialized with a pipeline.
If pipeline mode is not supported, will fall back to using transaction context manager.
"""
is_pooled_conn = isinstance(self.conn, AsyncConnectionPool)
# With AsyncConnectionPool, each _cursor() call checks out its own connection.
# The pool does not hand out the same connection concurrently, so a shared lock
# across calls is unnecessary here.
lock = asyncio.Lock() if is_pooled_conn else self.lock
async with _ainternal.get_connection(self.conn) as conn:
if self.pipe:
# a connection in pipeline mode can be used concurrently
@@ -566,21 +571,21 @@ class AsyncPostgresStore(AsyncBatchedBaseStore, BasePostgresStore[_ainternal.Con
# thread/coroutine at a time, so we acquire a lock
if self.supports_pipeline:
async with (
self.lock,
lock,
conn.pipeline(),
conn.cursor(binary=True, row_factory=dict_row) as cur,
):
yield cur
else:
async with (
self.lock,
lock,
conn.transaction(),
conn.cursor(binary=True, row_factory=dict_row) as cur,
):
yield cur
else:
async with (
self.lock,
lock,
conn.cursor(binary=True, row_factory=dict_row) as cur,
):
yield cur
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "langgraph-checkpoint-postgres"
version = "3.0.3"
version = "3.0.4"
description = "Library with a Postgres implementation of LangGraph checkpoint saver."
authors = []
requires-python = ">=3.10"
+1 -1
View File
@@ -306,7 +306,7 @@ test = [
[[package]]
name = "langgraph-checkpoint-postgres"
version = "3.0.3"
version = "3.0.4"
source = { editable = "." }
dependencies = [
{ name = "langgraph-checkpoint" },
+1 -1
View File
@@ -1600,7 +1600,7 @@ test = [
[[package]]
name = "langgraph-checkpoint-postgres"
version = "3.0.3"
version = "3.0.4"
source = { editable = "../checkpoint-postgres" }
dependencies = [
{ name = "langgraph-checkpoint" },
+1 -1
View File
@@ -399,7 +399,7 @@ test = [
[[package]]
name = "langgraph-checkpoint-postgres"
version = "3.0.3"
version = "3.0.4"
source = { editable = "../checkpoint-postgres" }
dependencies = [
{ name = "langgraph-checkpoint" },