psycopg.errors.LockNotAvailable: canceling statement due to lock timeout #630

Closed
opened 2026-02-20 17:41:01 -05:00 by yindo · 2 comments
Owner

Originally created by @Jackoder on GitHub (May 16, 2025).

Originally assigned to: @hinthornw on GitHub.

Checked other resources

  • This is a bug, not a usage question. For questions, please use GitHub Discussions.
  • I added a clear and detailed title that summarizes the issue.
  • I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example).
  • I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue.

Example Code

from typing import Optional
from src.models.openai import ChatOpenAI
from langgraph.graph import StateGraph, MessagesState
from langgraph.prebuilt import ToolNode
from langgraph.graph import StateGraph, MessagesState, START, END
from src.subgraph.rule.tools import tools

tool_node = ToolNode(tools)

model_with_tools = ChatOpenAI().bind_tools(tools)

class GraphState(MessagesState):
    nodes: Optional[str] = None
    question: Optional[str] = None
    knowledge: Optional[str] = None
    
    subgraph: Optional[str] = None
    node: Optional[str] = None
    chunks: Optional[list] = None
    rules: Optional[list] = None

def should_continue(state: GraphState):
    messages = state["messages"]
    last_message = messages[-1]
    if last_message.tool_calls:
        return "检索专家知识/规则"
    return END

def call_model(state: GraphState):
    messages = state["messages"]
    # some code ...
    response = model_with_tools.invoke(messages)
    return {"messages": [response]}

workflow = StateGraph(GraphState)

# Define the two nodes we will cycle between
workflow.add_node("节点知识/规则检查", call_model)
workflow.add_node("检索专家知识/规则", tool_node)

workflow.add_edge(START, "节点知识/规则检查")
workflow.add_conditional_edges("节点知识/规则检查", should_continue, ["检索专家知识/规则", END])
workflow.add_edge("检索专家知识/规则", "节点知识/规则检查")

graph = workflow.compile()

Error Message and Stack Trace (if applicable)

LockNotAvailable('canceling statement due to lock timeout\nCONTEXT:  while inserting index tuple (9038,11) in relation "checkpoint_blobs"')Traceback (most recent call last):


  File "/home/tomcat/.local/lib/python3.13/site-packages/langgraph/pregel/__init__.py", line 1668, in stream
    with SyncPregelLoop(
         ~~~~~~~~~~~~~~^
        input,
        ^^^^^^
    ...<11 lines>...
        debug=debug,
        ^^^^^^^^^^^^
    ) as loop:
    ^


  File "/home/tomcat/.local/lib/python3.13/site-packages/langgraph/pregel/loop.py", line 915, in __enter__
    saved = self.checkpointer.get_tuple(self.checkpoint_config)


  File "/usr/local/lib/python3.13/site-packages/langgraph_storage/checkpoint.py", line 459, in get_tuple
    ).result()
      ~~~~~~^^


  File "/usr/local/lib/python3.13/concurrent/futures/_base.py", line 456, in result
    return self.__get_result()
           ~~~~~~~~~~~~~~~~~^^


  File "/usr/local/lib/python3.13/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception


  File "/usr/local/lib/python3.13/site-packages/langgraph_storage/checkpoint.py", line 177, in aget_tuple
    return await anext(await self.aget_iter(config), None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


  File "/usr/local/lib/python3.13/site-packages/langgraph_storage/checkpoint.py", line 132, in <genexpr>
    return (
           ^
    ...<27 lines>...
    )
    ^


  File "/api/langgraph_api/asyncio.py", line 208, in aclosing_aiter


  File "/usr/local/lib/python3.13/site-packages/psycopg/cursor_async.py", line 240, in __aiter__
    await self._fetch_pipeline()


  File "/usr/local/lib/python3.13/site-packages/psycopg/cursor_async.py", line 298, in _fetch_pipeline
    await self._conn.wait(self._conn._pipeline._fetch_gen(flush=True))


  File "/usr/local/lib/python3.13/site-packages/psycopg/connection_async.py", line 432, in wait
    return await waiting.wait_async(gen, self.pgconn.socket, interval=interval)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


  File "/usr/local/lib/python3.13/site-packages/psycopg/waiting.py", line 158, in wait_async
    s = gen.send(ready)


  File "/usr/local/lib/python3.13/site-packages/psycopg/_pipeline.py", line 157, in _fetch_gen
    raise exception


  File "/usr/local/lib/python3.13/site-packages/psycopg/_pipeline.py", line 152, in _fetch_gen
    self._process_results(queued, results)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^


  File "/usr/local/lib/python3.13/site-packages/psycopg/_pipeline.py", line 179, in _process_results
    cursor._check_results(results)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^


  File "/usr/local/lib/python3.13/site-packages/psycopg/_cursor_base.py", line 470, in _check_results
    self._raise_for_result(res)
    ~~~~~~~~~~~~~~~~~~~~~~^^^^^


  File "/usr/local/lib/python3.13/site-packages/psycopg/_cursor_base.py", line 478, in _raise_for_result
    raise e.error_from_result(result, encoding=self._encoding)


psycopg.errors.LockNotAvailable: canceling statement due to lock timeout
CONTEXT:  while inserting index tuple (9038,11) in relation "checkpoint_blobs"

Description

I deployed two instances of Langgraph, both of which share the same Postgres database and Redis. Recently, I have noticed that timeout issues are quite common. How should this be resolved?

Also, I noticed in the documentation that 'The same database cannot be used for separate deployments.' Why can't we share the same database?(From url: https://langchain-ai.github.io/langgraph/concepts/langgraph_data_plane/?h=postgres#custom-postgres)

System Info

System Information

OS: Linux
OS Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
Python Version: 3.11.11 (main, Dec 4 2024, 08:55:08) [GCC 9.4.0]

Package Information

langchain_core: 0.3.47
langchain: 0.3.15
langchain_community: 0.3.15
langsmith: 0.3.8
langchain_anthropic: 0.3.7
langchain_deepseek: 0.1.2
langchain_fireworks: 0.2.5
langchain_mcp_adapters: 0.0.9
langchain_openai: 0.3.5
langchain_text_splitters: 0.3.6
langchainhub: 0.1.21
langgraph_api: 0.0.15
langgraph_cli: 0.1.65
langgraph_license: Installed. No version info available.
langgraph_sdk: 0.1.48
langgraph_storage: Installed. No version info available.
langserve: 0.3.0

Other Dependencies

aiohttp: 3.11.10
anthropic<1,>=0.45.0: Installed. No version info available.
async-timeout: Installed. No version info available.
click: 8.1.7
cryptography: 43.0.3
dataclasses-json: 0.6.7
fastapi: 0.115.6
fireworks-ai: 0.15.10
httpx: 0.28.1
httpx-sse: 0.4.0
jsonpatch<2.0,>=1.33: Installed. No version info available.
jsonschema-rs: 0.25.1
langchain-core<0.4,>=0.3.36: Installed. No version info available.
langchain-core<1.0.0,>=0.3.34: Installed. No version info available.
langchain-openai<1.0.0,>=0.3.5: Installed. No version info available.
langgraph: 0.3.34
langgraph-checkpoint: 2.0.25
langsmith-pyo3: Installed. No version info available.
langsmith<0.4,>=0.1.125: Installed. No version info available.
mcp<1.7,>=1.4.1: Installed. No version info available.
numpy: 1.26.4
openai: 1.68.2
openai<2.0.0,>=1.58.1: Installed. No version info available.
orjson: 3.10.12
packaging: 24.2
packaging<25,>=23.2: Installed. No version info available.
pydantic: 2.10.3
pydantic-settings: 2.6.1
pydantic<3.0.0,>=2.5.2;: Installed. No version info available.
pydantic<3.0.0,>=2.7.4: Installed. No version info available.
pydantic<3.0.0,>=2.7.4;: Installed. No version info available.
pyjwt: 2.10.1
pytest: Installed. No version info available.
python-dotenv: 1.0.1
PyYAML: 6.0.2
PyYAML>=5.3: Installed. No version info available.
requests: 2.28.0
requests-toolbelt: 1.0.0
rich: 13.9.4
SQLAlchemy: 2.0.36
sse-starlette: 2.1.3
starlette: 0.41.3
structlog: 24.4.0
tenacity: 8.5.0
tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
tiktoken<1,>=0.7: Installed. No version info available.
types-requests: 2.32.0.20241016
typing-extensions>=4.7: Installed. No version info available.
uvicorn: 0.32.1
watchfiles: 1.0.0
zstandard: 0.23.0

Originally created by @Jackoder on GitHub (May 16, 2025). Originally assigned to: @hinthornw on GitHub. ### Checked other resources - [x] This is a bug, not a usage question. For questions, please use GitHub Discussions. - [x] I added a clear and detailed title that summarizes the issue. - [x] I read what a minimal reproducible example is (https://stackoverflow.com/help/minimal-reproducible-example). - [x] I included a self-contained, minimal example that demonstrates the issue INCLUDING all the relevant imports. The code run AS IS to reproduce the issue. ### Example Code ```python from typing import Optional from src.models.openai import ChatOpenAI from langgraph.graph import StateGraph, MessagesState from langgraph.prebuilt import ToolNode from langgraph.graph import StateGraph, MessagesState, START, END from src.subgraph.rule.tools import tools tool_node = ToolNode(tools) model_with_tools = ChatOpenAI().bind_tools(tools) class GraphState(MessagesState): nodes: Optional[str] = None question: Optional[str] = None knowledge: Optional[str] = None subgraph: Optional[str] = None node: Optional[str] = None chunks: Optional[list] = None rules: Optional[list] = None def should_continue(state: GraphState): messages = state["messages"] last_message = messages[-1] if last_message.tool_calls: return "检索专家知识/规则" return END def call_model(state: GraphState): messages = state["messages"] # some code ... response = model_with_tools.invoke(messages) return {"messages": [response]} workflow = StateGraph(GraphState) # Define the two nodes we will cycle between workflow.add_node("节点知识/规则检查", call_model) workflow.add_node("检索专家知识/规则", tool_node) workflow.add_edge(START, "节点知识/规则检查") workflow.add_conditional_edges("节点知识/规则检查", should_continue, ["检索专家知识/规则", END]) workflow.add_edge("检索专家知识/规则", "节点知识/规则检查") graph = workflow.compile() ``` ### Error Message and Stack Trace (if applicable) ```shell LockNotAvailable('canceling statement due to lock timeout\nCONTEXT: while inserting index tuple (9038,11) in relation "checkpoint_blobs"')Traceback (most recent call last): File "/home/tomcat/.local/lib/python3.13/site-packages/langgraph/pregel/__init__.py", line 1668, in stream with SyncPregelLoop( ~~~~~~~~~~~~~~^ input, ^^^^^^ ...<11 lines>... debug=debug, ^^^^^^^^^^^^ ) as loop: ^ File "/home/tomcat/.local/lib/python3.13/site-packages/langgraph/pregel/loop.py", line 915, in __enter__ saved = self.checkpointer.get_tuple(self.checkpoint_config) File "/usr/local/lib/python3.13/site-packages/langgraph_storage/checkpoint.py", line 459, in get_tuple ).result() ~~~~~~^^ File "/usr/local/lib/python3.13/concurrent/futures/_base.py", line 456, in result return self.__get_result() ~~~~~~~~~~~~~~~~~^^ File "/usr/local/lib/python3.13/concurrent/futures/_base.py", line 401, in __get_result raise self._exception File "/usr/local/lib/python3.13/site-packages/langgraph_storage/checkpoint.py", line 177, in aget_tuple return await anext(await self.aget_iter(config), None) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.13/site-packages/langgraph_storage/checkpoint.py", line 132, in <genexpr> return ( ^ ...<27 lines>... ) ^ File "/api/langgraph_api/asyncio.py", line 208, in aclosing_aiter File "/usr/local/lib/python3.13/site-packages/psycopg/cursor_async.py", line 240, in __aiter__ await self._fetch_pipeline() File "/usr/local/lib/python3.13/site-packages/psycopg/cursor_async.py", line 298, in _fetch_pipeline await self._conn.wait(self._conn._pipeline._fetch_gen(flush=True)) File "/usr/local/lib/python3.13/site-packages/psycopg/connection_async.py", line 432, in wait return await waiting.wait_async(gen, self.pgconn.socket, interval=interval) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.13/site-packages/psycopg/waiting.py", line 158, in wait_async s = gen.send(ready) File "/usr/local/lib/python3.13/site-packages/psycopg/_pipeline.py", line 157, in _fetch_gen raise exception File "/usr/local/lib/python3.13/site-packages/psycopg/_pipeline.py", line 152, in _fetch_gen self._process_results(queued, results) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.13/site-packages/psycopg/_pipeline.py", line 179, in _process_results cursor._check_results(results) ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "/usr/local/lib/python3.13/site-packages/psycopg/_cursor_base.py", line 470, in _check_results self._raise_for_result(res) ~~~~~~~~~~~~~~~~~~~~~~^^^^^ File "/usr/local/lib/python3.13/site-packages/psycopg/_cursor_base.py", line 478, in _raise_for_result raise e.error_from_result(result, encoding=self._encoding) psycopg.errors.LockNotAvailable: canceling statement due to lock timeout CONTEXT: while inserting index tuple (9038,11) in relation "checkpoint_blobs" ``` ### Description I deployed two instances of Langgraph, both of which share the same Postgres database and Redis. Recently, I have noticed that timeout issues are quite common. How should this be resolved? Also, I noticed in the documentation that 'The same database cannot be used for separate deployments.' Why can't we share the same database?(From url: https://langchain-ai.github.io/langgraph/concepts/langgraph_data_plane/?h=postgres#custom-postgres) ### System Info System Information ------------------ > OS: Linux > OS Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024 > Python Version: 3.11.11 (main, Dec 4 2024, 08:55:08) [GCC 9.4.0] Package Information ------------------- > langchain_core: 0.3.47 > langchain: 0.3.15 > langchain_community: 0.3.15 > langsmith: 0.3.8 > langchain_anthropic: 0.3.7 > langchain_deepseek: 0.1.2 > langchain_fireworks: 0.2.5 > langchain_mcp_adapters: 0.0.9 > langchain_openai: 0.3.5 > langchain_text_splitters: 0.3.6 > langchainhub: 0.1.21 > langgraph_api: 0.0.15 > langgraph_cli: 0.1.65 > langgraph_license: Installed. No version info available. > langgraph_sdk: 0.1.48 > langgraph_storage: Installed. No version info available. > langserve: 0.3.0 Other Dependencies ------------------ > aiohttp: 3.11.10 > anthropic<1,>=0.45.0: Installed. No version info available. > async-timeout: Installed. No version info available. > click: 8.1.7 > cryptography: 43.0.3 > dataclasses-json: 0.6.7 > fastapi: 0.115.6 > fireworks-ai: 0.15.10 > httpx: 0.28.1 > httpx-sse: 0.4.0 > jsonpatch<2.0,>=1.33: Installed. No version info available. > jsonschema-rs: 0.25.1 > langchain-core<0.4,>=0.3.36: Installed. No version info available. > langchain-core<1.0.0,>=0.3.34: Installed. No version info available. > langchain-openai<1.0.0,>=0.3.5: Installed. No version info available. > langgraph: 0.3.34 > langgraph-checkpoint: 2.0.25 > langsmith-pyo3: Installed. No version info available. > langsmith<0.4,>=0.1.125: Installed. No version info available. > mcp<1.7,>=1.4.1: Installed. No version info available. > numpy: 1.26.4 > openai: 1.68.2 > openai<2.0.0,>=1.58.1: Installed. No version info available. > orjson: 3.10.12 > packaging: 24.2 > packaging<25,>=23.2: Installed. No version info available. > pydantic: 2.10.3 > pydantic-settings: 2.6.1 > pydantic<3.0.0,>=2.5.2;: Installed. No version info available. > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic<3.0.0,>=2.7.4;: Installed. No version info available. > pyjwt: 2.10.1 > pytest: Installed. No version info available. > python-dotenv: 1.0.1 > PyYAML: 6.0.2 > PyYAML>=5.3: Installed. No version info available. > requests: 2.28.0 > requests-toolbelt: 1.0.0 > rich: 13.9.4 > SQLAlchemy: 2.0.36 > sse-starlette: 2.1.3 > starlette: 0.41.3 > structlog: 24.4.0 > tenacity: 8.5.0 > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > tiktoken<1,>=0.7: Installed. No version info available. > types-requests: 2.32.0.20241016 > typing-extensions>=4.7: Installed. No version info available. > uvicorn: 0.32.1 > watchfiles: 1.0.0 > zstandard: 0.23.0
yindo added the question label 2026-02-20 17:41:01 -05:00
yindo closed this issue 2026-02-20 17:41:01 -05:00
Author
Owner

@hinthornw commented on GitHub (Jun 11, 2025):

I believe we've fixed this in a deployment last Friday. Please let me know if you still see this issue, however!

@hinthornw commented on GitHub (Jun 11, 2025): I believe we've fixed this in a deployment last Friday. Please let me know if you still see this issue, however!
Author
Owner

@ivorpad commented on GitHub (Jun 13, 2025):

I'm still seeing this @hinthornw

LockNotAvailable('canceling statement due to lock timeout')Traceback (most recent call last):


  File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 2655, in astream
    async for _ in runner.atick(


  File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 2788, in ainvoke
    async for chunk in self.astream(


  File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 2596, in astream
    async with AsyncPregelLoop(


  File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/loop.py", line 1393, in __aexit__
    return await exit_task
           ^^^^^^^^^^^^^^^


  File "/usr/local/lib/python3.11/contextlib.py", line 745, in __aexit__
    raise exc_details[1]


  File "/usr/local/lib/python3.11/contextlib.py", line 728, in __aexit__
    cb_suppress = await cb(*exc_details)
                  ^^^^^^^^^^^^^^^^^^^^^^


  File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/executor.py", line 209, in __aexit__
    raise exc


  File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/loop.py", line 1260, in _checkpointer_put_after_previous
    await prev


  File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/loop.py", line 1260, in _checkpointer_put_after_previous
    await prev


  File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/loop.py", line 1262, in _checkpointer_put_after_previous
    await cast(BaseCheckpointSaver, self.checkpointer).aput(


  File "/usr/local/lib/python3.11/site-packages/langgraph_runtime_postgres/checkpoint.py", line 253, in aput


  File "/usr/local/lib/python3.11/site-packages/psycopg/cursor_async.py", line 97, in execute
    raise ex.with_traceback(None)


psycopg.errors.LockNotAvailable: canceling statement due to lock timeout


During task with name 'qa_grading' and id '5fab9c41-5391-de49-bbab-9647106ca72e'
@ivorpad commented on GitHub (Jun 13, 2025): I'm still seeing this @hinthornw ```bash LockNotAvailable('canceling statement due to lock timeout')Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 2655, in astream async for _ in runner.atick( File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 2788, in ainvoke async for chunk in self.astream( File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/__init__.py", line 2596, in astream async with AsyncPregelLoop( File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/loop.py", line 1393, in __aexit__ return await exit_task ^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/contextlib.py", line 745, in __aexit__ raise exc_details[1] File "/usr/local/lib/python3.11/contextlib.py", line 728, in __aexit__ cb_suppress = await cb(*exc_details) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/executor.py", line 209, in __aexit__ raise exc File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/loop.py", line 1260, in _checkpointer_put_after_previous await prev File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/loop.py", line 1260, in _checkpointer_put_after_previous await prev File "/usr/local/lib/python3.11/site-packages/langgraph/pregel/loop.py", line 1262, in _checkpointer_put_after_previous await cast(BaseCheckpointSaver, self.checkpointer).aput( File "/usr/local/lib/python3.11/site-packages/langgraph_runtime_postgres/checkpoint.py", line 253, in aput File "/usr/local/lib/python3.11/site-packages/psycopg/cursor_async.py", line 97, in execute raise ex.with_traceback(None) psycopg.errors.LockNotAvailable: canceling statement due to lock timeout During task with name 'qa_grading' and id '5fab9c41-5391-de49-bbab-9647106ca72e' ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#630