mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-20 14:41:05 +08:00
Fix: close MCP sessions after canvas execution to prevent connection leaks
Add Graph.close() method that finds and closes all MCPToolCallSessions held by Agent components. Call it in finally blocks after canvas.run() in canvas_service.py and canvas_app.py. Also move session cleanup to finally blocks in test_tool endpoint and get_mcp_tools to ensure sessions are closed even on exceptions.
This commit is contained in:
@@ -137,6 +137,20 @@ class Graph:
|
||||
except Exception as e:
|
||||
logging.exception(e)
|
||||
|
||||
def close(self):
|
||||
from common.mcp_tool_call_conn import MCPToolCallSession
|
||||
seen = set()
|
||||
for cpn in self.components.values():
|
||||
obj = cpn.get("obj")
|
||||
if obj and hasattr(obj, "tools"):
|
||||
for tool in obj.tools.values():
|
||||
if isinstance(tool, MCPToolCallSession) and id(tool) not in seen:
|
||||
seen.add(id(tool))
|
||||
try:
|
||||
tool.close_sync(timeout=3)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def get_component_name(self, cid):
|
||||
for n in self.dsl.get("graph", {}).get("nodes", []):
|
||||
if cid == n["id"]:
|
||||
|
||||
Reference in New Issue
Block a user