consuming input failed: server closed the connection unexpectedly #647

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

Originally created by @khteh on GitHub (May 27, 2025).

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

    try:
        async for step in current_app.agent.astream(
            {"messages": [{"role": "user", "content": user_input['message']}]},
             stream_mode="values", # Use this to stream all values in the state after each step.
            config = config, # This is needed by Checkpointer
        ):
            result.append(step["messages"][-1])
            step["messages"][-1].pretty_print()
        ai_message: ChatMessage = None
        if len(result):
            ai_message = ChatMessage.from_langchain(result[-1])
            if ai_message and not ai_message.tool_calls and ai_message.content and len(ai_message.content):
                logging.debug(f"/invoke respose: {ai_message.content}")
                return custom_response({"message": ai_message.content}, 200)
        return custom_response({"message": ""}, 503)
    except Exception as e:
        logging.exception(f"/invoke exception! {str(e)}, repr: {repr(e)}")

Error Message and Stack Trace (if applicable)

2025-05-27 14:34:03 ERROR    /invoke exception! consuming input failed: server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request., repr: OperationalError('consuming input failed: server closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbefore or while processing the request.')
Traceback (most recent call last):
  File "/usr/src/Python/rag-agent/src/controllers/HomeController.py", line 139, in invoke
    async for step in current_app.agent.astream(
    ...<5 lines>...
        step["messages"][-1].pretty_print()
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langgraph/pregel/__init__.py", line 2771, in astream
    async with AsyncPregelLoop(
               ~~~~~~~~~~~~~~~^
        input,
        ^^^^^^
    ...<20 lines>...
        cache_policy=self.cache_policy,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ) as loop:
    ^
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langgraph/pregel/loop.py", line 1382, in __aexit__
    return await exit_task
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/contextlib.py", line 768, in __aexit__
    raise exc
  File "/usr/lib/python3.13/contextlib.py", line 751, in __aexit__
    cb_suppress = await cb(*exc_details)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langgraph/pregel/executor.py", line 209, in __aexit__
    raise exc
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langgraph/checkpoint/postgres/aio.py", line 315, in aput_writes
    await cur.executemany(query, params)
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/psycopg/cursor_async.py", line 127, in executemany
    raise ex.with_traceback(None)
psycopg.OperationalError: consuming input failed: server closed the connection unexpectedly
	This probably means the server terminated abnormally
	before or while processing the request.
2025-05-27 14:34:03 WARNING  discarding closed connection: <psycopg.AsyncConnection [BAD] at 0x732c38fff850>

Description

create_react_agent using llama3.3, in-memory store, PostgreSQL vector. I am shocked to find out that the PG vector store embeddings langchain_pg_embedding table is cleared out of nowhere when this exception happens! This is PG log:

2025-05-27 06:28:33.536 UTC [1] LOG:  server process (PID 56306) was terminated by signal 9: Killed
2025-05-27 06:28:33.536 UTC [1] DETAIL:  Failed process was running: /*pga4dash*/
	SELECT 'session_stats' AS chart_name, pg_catalog.row_to_json(t) AS chart_data
	FROM (SELECT
	   (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388)) AS "Total",
	   (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE state = 'active' AND datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388))  AS "Active",
	   (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE state = 'idle' AND datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388))  AS "Idle"
	) t
	UNION ALL
	SELECT 'tps_stats' AS chart_name, pg_catalog.row_to_json(t) AS chart_data
	FROM (SELECT
	   (SELECT sum(xact_commit) + sum(xact_rollback) FROM pg_catalog.pg_stat_database WHERE datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388)) AS "Transactions",
	   (SELECT sum(xact_commit) FROM pg_catalog.pg_stat_database WHERE datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388)) AS "Commits",
	   (SE

System Info

System Information
------------------
> OS:  Linux
> OS Version:  #15-Ubuntu SMP PREEMPT_DYNAMIC Sun Apr  6 15:05:05 UTC 2025
> Python Version:  3.13.3 (main, Apr  8 2025, 19:55:40) [GCC 14.2.0]

Package Information
-------------------
> langchain_core: 0.3.60
> langchain: 0.3.25
> langchain_community: 0.3.24
> langsmith: 0.3.42
> langchain_chroma: 0.2.4
> langchain_google_genai: 2.1.4
> langchain_neo4j: 0.4.0
> langchain_nomic: 0.1.4
> langchain_ollama: 0.3.3
> langchain_openai: 0.3.17
> langchain_postgres: 0.0.13
> langchain_text_splitters: 0.3.8
> langgraph_sdk: 0.1.69

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp<4.0.0,>=3.8.3: Installed. No version info available.
> async-timeout<5.0.0,>=4.0.0;: Installed. No version info available.
> chromadb>=1.0.9: Installed. No version info available.
> dataclasses-json<0.7,>=0.5.7: Installed. No version info available.
> filetype: 1.2.0
> google-ai-generativelanguage: 0.6.18
> httpx: 0.28.1
> httpx-sse<1.0.0,>=0.4.0: Installed. No version info available.
> jsonpatch<2.0,>=1.33: Installed. No version info available.
> langchain-anthropic;: Installed. No version info available.
> langchain-aws;: Installed. No version info available.
> langchain-azure-ai;: Installed. No version info available.
> langchain-cohere;: Installed. No version info available.
> langchain-community;: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.51: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.58: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.59: Installed. No version info available.
> langchain-core<1.0.0,>=0.3.60: Installed. No version info available.
> langchain-core>=0.3.60: Installed. No version info available.
> langchain-deepseek;: Installed. No version info available.
> langchain-fireworks;: Installed. No version info available.
> langchain-google-genai;: Installed. No version info available.
> langchain-google-vertexai;: Installed. No version info available.
> langchain-groq;: Installed. No version info available.
> langchain-huggingface;: Installed. No version info available.
> langchain-mistralai;: Installed. No version info available.
> langchain-ollama;: Installed. No version info available.
> langchain-openai;: Installed. No version info available.
> langchain-perplexity;: Installed. No version info available.
> langchain-text-splitters<1.0.0,>=0.3.8: Installed. No version info available.
> langchain-together;: Installed. No version info available.
> langchain-xai;: Installed. No version info available.
> langchain<1.0.0,>=0.3.25: Installed. No version info available.
> langsmith-pyo3: Installed. No version info available.
> langsmith<0.4,>=0.1.125: Installed. No version info available.
> langsmith<0.4,>=0.1.126: Installed. No version info available.
> langsmith<0.4,>=0.1.17: Installed. No version info available.
> neo4j: 5.28.1
> neo4j-graphrag: 1.6.1
> nomic: 3.5.1
> numpy: 2.2.5
> numpy>=1.26.0;: Installed. No version info available.
> numpy>=1.26.2;: Installed. No version info available.
> numpy>=2.1.0;: Installed. No version info available.
> ollama<1.0.0,>=0.4.8: Installed. No version info available.
> openai-agents: Installed. No version info available.
> openai<2.0.0,>=1.68.2: Installed. No version info available.
> opentelemetry-api: 1.33.0
> opentelemetry-exporter-otlp-proto-http: Installed. No version info available.
> opentelemetry-sdk: 1.33.0
> orjson: 3.10.18
> packaging: 24.2
> packaging<25,>=23.2: Installed. No version info available.
> pgvector: 0.3.6
> pillow: 10.4.0
> psycopg: 3.2.9
> psycopg-pool: 3.2.6
> pydantic: 2.11.4
> pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available.
> pydantic<3.0.0,>=2.7.4: Installed. No version info available.
> pydantic>=2.7.4: Installed. No version info available.
> pytest: Installed. No version info available.
> PyYAML>=5.3: Installed. No version info available.
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> requests<3,>=2: Installed. No version info available.
> rich: 14.0.0
> sqlalchemy: 2.0.41
> SQLAlchemy<3,>=1.4: Installed. No version info available.
> tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available.
> tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available.
> tiktoken<1,>=0.7: Installed. No version info available.
> typing-extensions>=4.7: Installed. No version info available.
> zstandard: 0.23.0
Originally created by @khteh on GitHub (May 27, 2025). ### 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 try: async for step in current_app.agent.astream( {"messages": [{"role": "user", "content": user_input['message']}]}, stream_mode="values", # Use this to stream all values in the state after each step. config = config, # This is needed by Checkpointer ): result.append(step["messages"][-1]) step["messages"][-1].pretty_print() ai_message: ChatMessage = None if len(result): ai_message = ChatMessage.from_langchain(result[-1]) if ai_message and not ai_message.tool_calls and ai_message.content and len(ai_message.content): logging.debug(f"/invoke respose: {ai_message.content}") return custom_response({"message": ai_message.content}, 200) return custom_response({"message": ""}, 503) except Exception as e: logging.exception(f"/invoke exception! {str(e)}, repr: {repr(e)}") ``` ### Error Message and Stack Trace (if applicable) ```shell 2025-05-27 14:34:03 ERROR /invoke exception! consuming input failed: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request., repr: OperationalError('consuming input failed: server closed the connection unexpectedly\n\tThis probably means the server terminated abnormally\n\tbefore or while processing the request.') Traceback (most recent call last): File "/usr/src/Python/rag-agent/src/controllers/HomeController.py", line 139, in invoke async for step in current_app.agent.astream( ...<5 lines>... step["messages"][-1].pretty_print() File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langgraph/pregel/__init__.py", line 2771, in astream async with AsyncPregelLoop( ~~~~~~~~~~~~~~~^ input, ^^^^^^ ...<20 lines>... cache_policy=self.cache_policy, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) as loop: ^ File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langgraph/pregel/loop.py", line 1382, in __aexit__ return await exit_task ^^^^^^^^^^^^^^^ File "/usr/lib/python3.13/contextlib.py", line 768, in __aexit__ raise exc File "/usr/lib/python3.13/contextlib.py", line 751, in __aexit__ cb_suppress = await cb(*exc_details) ^^^^^^^^^^^^^^^^^^^^^^ File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langgraph/pregel/executor.py", line 209, in __aexit__ raise exc File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langgraph/checkpoint/postgres/aio.py", line 315, in aput_writes await cur.executemany(query, params) File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/psycopg/cursor_async.py", line 127, in executemany raise ex.with_traceback(None) psycopg.OperationalError: consuming input failed: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. 2025-05-27 14:34:03 WARNING discarding closed connection: <psycopg.AsyncConnection [BAD] at 0x732c38fff850> ``` ### Description `create_react_agent` using `llama3.3`, in-memory store, PostgreSQL vector. I am shocked to find out that the PG vector store embeddings `langchain_pg_embedding` table is cleared out of nowhere when this exception happens! This is PG log: ``` 2025-05-27 06:28:33.536 UTC [1] LOG: server process (PID 56306) was terminated by signal 9: Killed 2025-05-27 06:28:33.536 UTC [1] DETAIL: Failed process was running: /*pga4dash*/ SELECT 'session_stats' AS chart_name, pg_catalog.row_to_json(t) AS chart_data FROM (SELECT (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388)) AS "Total", (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE state = 'active' AND datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388)) AS "Active", (SELECT count(*) FROM pg_catalog.pg_stat_activity WHERE state = 'idle' AND datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388)) AS "Idle" ) t UNION ALL SELECT 'tps_stats' AS chart_name, pg_catalog.row_to_json(t) AS chart_data FROM (SELECT (SELECT sum(xact_commit) + sum(xact_rollback) FROM pg_catalog.pg_stat_database WHERE datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388)) AS "Transactions", (SELECT sum(xact_commit) FROM pg_catalog.pg_stat_database WHERE datname = (SELECT datname FROM pg_catalog.pg_database WHERE oid = 16388)) AS "Commits", (SE ``` ### System Info ``` System Information ------------------ > OS: Linux > OS Version: #15-Ubuntu SMP PREEMPT_DYNAMIC Sun Apr 6 15:05:05 UTC 2025 > Python Version: 3.13.3 (main, Apr 8 2025, 19:55:40) [GCC 14.2.0] Package Information ------------------- > langchain_core: 0.3.60 > langchain: 0.3.25 > langchain_community: 0.3.24 > langsmith: 0.3.42 > langchain_chroma: 0.2.4 > langchain_google_genai: 2.1.4 > langchain_neo4j: 0.4.0 > langchain_nomic: 0.1.4 > langchain_ollama: 0.3.3 > langchain_openai: 0.3.17 > langchain_postgres: 0.0.13 > langchain_text_splitters: 0.3.8 > langgraph_sdk: 0.1.69 Optional packages not installed ------------------------------- > langserve Other Dependencies ------------------ > aiohttp<4.0.0,>=3.8.3: Installed. No version info available. > async-timeout<5.0.0,>=4.0.0;: Installed. No version info available. > chromadb>=1.0.9: Installed. No version info available. > dataclasses-json<0.7,>=0.5.7: Installed. No version info available. > filetype: 1.2.0 > google-ai-generativelanguage: 0.6.18 > httpx: 0.28.1 > httpx-sse<1.0.0,>=0.4.0: Installed. No version info available. > jsonpatch<2.0,>=1.33: Installed. No version info available. > langchain-anthropic;: Installed. No version info available. > langchain-aws;: Installed. No version info available. > langchain-azure-ai;: Installed. No version info available. > langchain-cohere;: Installed. No version info available. > langchain-community;: Installed. No version info available. > langchain-core<1.0.0,>=0.3.51: Installed. No version info available. > langchain-core<1.0.0,>=0.3.58: Installed. No version info available. > langchain-core<1.0.0,>=0.3.59: Installed. No version info available. > langchain-core<1.0.0,>=0.3.60: Installed. No version info available. > langchain-core>=0.3.60: Installed. No version info available. > langchain-deepseek;: Installed. No version info available. > langchain-fireworks;: Installed. No version info available. > langchain-google-genai;: Installed. No version info available. > langchain-google-vertexai;: Installed. No version info available. > langchain-groq;: Installed. No version info available. > langchain-huggingface;: Installed. No version info available. > langchain-mistralai;: Installed. No version info available. > langchain-ollama;: Installed. No version info available. > langchain-openai;: Installed. No version info available. > langchain-perplexity;: Installed. No version info available. > langchain-text-splitters<1.0.0,>=0.3.8: Installed. No version info available. > langchain-together;: Installed. No version info available. > langchain-xai;: Installed. No version info available. > langchain<1.0.0,>=0.3.25: Installed. No version info available. > langsmith-pyo3: Installed. No version info available. > langsmith<0.4,>=0.1.125: Installed. No version info available. > langsmith<0.4,>=0.1.126: Installed. No version info available. > langsmith<0.4,>=0.1.17: Installed. No version info available. > neo4j: 5.28.1 > neo4j-graphrag: 1.6.1 > nomic: 3.5.1 > numpy: 2.2.5 > numpy>=1.26.0;: Installed. No version info available. > numpy>=1.26.2;: Installed. No version info available. > numpy>=2.1.0;: Installed. No version info available. > ollama<1.0.0,>=0.4.8: Installed. No version info available. > openai-agents: Installed. No version info available. > openai<2.0.0,>=1.68.2: Installed. No version info available. > opentelemetry-api: 1.33.0 > opentelemetry-exporter-otlp-proto-http: Installed. No version info available. > opentelemetry-sdk: 1.33.0 > orjson: 3.10.18 > packaging: 24.2 > packaging<25,>=23.2: Installed. No version info available. > pgvector: 0.3.6 > pillow: 10.4.0 > psycopg: 3.2.9 > psycopg-pool: 3.2.6 > pydantic: 2.11.4 > pydantic-settings<3.0.0,>=2.4.0: Installed. No version info available. > pydantic<3.0.0,>=2.7.4: Installed. No version info available. > pydantic>=2.7.4: Installed. No version info available. > pytest: Installed. No version info available. > PyYAML>=5.3: Installed. No version info available. > requests: 2.32.3 > requests-toolbelt: 1.0.0 > requests<3,>=2: Installed. No version info available. > rich: 14.0.0 > sqlalchemy: 2.0.41 > SQLAlchemy<3,>=1.4: Installed. No version info available. > tenacity!=8.4.0,<10,>=8.1.0: Installed. No version info available. > tenacity!=8.4.0,<10.0.0,>=8.1.0: Installed. No version info available. > tiktoken<1,>=0.7: Installed. No version info available. > typing-extensions>=4.7: Installed. No version info available. > zstandard: 0.23.0 ```
yindo closed this issue 2026-02-20 17:41:07 -05:00
Author
Owner

@vbarda commented on GitHub (May 27, 2025):

could you provide full reproducible example (with the graph and checkpointer definition)?

@vbarda commented on GitHub (May 27, 2025): could you provide full reproducible example (with the graph and checkpointer definition)?
Author
Owner

@khteh commented on GitHub (May 28, 2025):

What happens when the CSRF token expires in the middle of the chain processing?

@khteh commented on GitHub (May 28, 2025): What happens when the CSRF token expires in the middle of the chain processing?
Author
Owner

@sydney-runkle commented on GitHub (May 29, 2025):

Closing for now with no MRE, feel free to reopen a new issue with one!

@sydney-runkle commented on GitHub (May 29, 2025): Closing for now with no MRE, feel free to reopen a new issue with one!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#647