Skip to content

fix(plugin): prevent hang on PluginInvokeError via iterative unwrap - #38955

Open
bailong-Hakuryu wants to merge 2 commits into
langgenius:mainfrom
bailong-Hakuryu:fix/issue-38912-plugin-invoke-error
Open

fix(plugin): prevent hang on PluginInvokeError via iterative unwrap#38955
bailong-Hakuryu wants to merge 2 commits into
langgenius:mainfrom
bailong-Hakuryu:fix/issue-38912-plugin-invoke-error

Conversation

@bailong-Hakuryu

Copy link
Copy Markdown

Problem

When an Agent node invokes a plugin tool in a Chatflow, the API service hangs and eventually returns PluginInvokeError: {"message": "invocation exited without response"} after timeout.

Closes #38912

Root Cause

unwrap_plugin_daemon_error used recursive calls to peel nested PluginInvokeError payloads. A pathological or cyclic error chain could exhaust the stack and block the event loop.

Changes

  • plugin_daemon_transport.py: Replace recursive unwrap with a bounded iterative loop (cap: MAX_UNWRAP_DEPTH=5, env-configurable). Fix from __future__ import annotations placement (was after import os, causing SyntaxError).'
  • tool_client.py: Add raw_payload attribute to DifyPluginToolClientError and forward it through _raise_tool_daemon_error so callers retain the original daemon response body for debugging.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 14, 2026
@bailong-Hakuryu
bailong-Hakuryu marked this pull request as draft July 14, 2026 14:12
@bailong-Hakuryu
bailong-Hakuryu marked this pull request as ready for review July 14, 2026 14:37
@sdkrre

sdkrre commented Jul 20, 2026

Copy link
Copy Markdown

@bailong-Hakuryu I tried using it and added the code you provided into v1.15.0, but it still seems to hang. Is there anything else I can fix?

@bailong-Hakuryu

Copy link
Copy Markdown
Author

我试过用它,把你提供的代码加到了v1.15.0,但它还是卡住了。还有什么我可以解决的吗?

I have updated the PR to address the underlying API hang issue.

In base_session.py, queue.Empty handling was previously entering an infinite while True: loop when waiting for MCP server responses if the receiver task remained open, ignoring read timeouts and keeping API worker greenlets blocked. An explicit max_timeout deadline check is now enforced.
Added default 60s fallback timeouts in mcp_tool/tool.py when invoking MCPClientWithAuthRetry to ensure unhandled timeouts cleanly terminate without starving Gunicorn worker connections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API Service Hangs When Using Agent Node in Chatflow

2 participants