Skip to content

MCP服务器禁用时触发处理器100%占用 #9068

Description

@GlowingBrick

What happened / 发生了什么

禁用任意mcp服务器后,top中看到:
PID 用户 优 NI 虚拟 驻留 共享 S %CPU %MEM 时间+ 命令
44399 brick 20 0 2381272 276708 44048 R 99.4 1.7 7:14.39 astrbot

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
14533 root 20 0 2363032 295888 43488 R 99.7 3.8 38:41.75 astrbot

且持续存在,除非重启

Reproduce / 如何复现?

禁用一个mcp服务器。测试了paddle_ocr和agent-browser mcp均会触发

可能的原因:
AstrBot 为每个 MCP Server 创建一个生命周期任务来管理连接。当禁用 MCP 时,生命周期任务调用清理方法关闭资源。但连接是在另一个任务中建立的,导致 anyio 的取消作用域(CancelScope)在退出时检测到"非本任务创建的任务"并报错。这个错误被静默捕获,导致 anyio 的任务组处于半清理状态,残留的取消作用域无法被正确释放。
MCP Client 在重连时,旧的 AsyncExitStack 被保存到列表中但从未关闭。每个残留的 AsyncExitStack 都持有仍在运行的 anyio 任务组(来自 stdio_client)。这些孤立的任务组在遇到错误时会触发上述的无限循环,从而吃满处理器资源。

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

在两个平台上测试过,均稳定复现:

  • Arch Linux x86_64 ,Linux Brick-PC 7.0.13-zen1-1-zen
  • Debian GNU/Linux 13 (trixie) aarch ,Linux localhost 4.19.325-cip128-st12-perf-ge18cd3944894

测试版本:

  • astrbot==4.25.6
  • astrbot==4.26.2

部署方式

  • uv tool

OS

Linux

Logs / 报错日志

$astrbot run

     ___           _______.___________..______      .______     ______   .___________.
    /   \         /       |           ||   _  \     |   _  \   /  __  \  |           |
   /  ^  \       |   (----`---|  |----`|  |_)  |    |  |_)  | |  |  |  | `---|  |----`
  /  /_\  \       \   \       |  |     |      /     |   _  <  |  |  |  |     |  |
 /  _____  \  .----)   |      |  |     |  |\  \----.|  |_)  | |  `--'  |     |  |
/__/     \__\ |_______/       |__|     | _| `._____||______/   \______/      |__|

Welcome to AstrBot CLI!
AstrBot CLI version: 4.26.2
[18:01:29.563] [Core] [INFO] [config.astrbot_config:178]: Config key missing; added default.
[18:01:29.564] [Core] [INFO] [config.astrbot_config:178]: Config key missing; added default.
[18:01:29.564] [Core] [INFO] [config.astrbot_config:214]: Config key order fixed: provider_settings
[18:01:32.621] [Core] [DBUG] [platform.register:60]: Platform adapter registered: wecom_ai_bot
[18:01:32.628] [Core] [DBUG] [platform.register:60]: Platform adapter registered: webchat
Dashboard is bundled with the package – skipping download.
[18:01:33.215] [Core] [DBUG] [core.core_lifecycle:81]: HTTP proxy cleared
[18:01:33.215] [Core] [INFO] [core.core_lifecycle:148]: AstrBot v4.26.2
[18:01:33.292] [Core] [INFO] [core.persona_mgr:38]: Loaded 0 personas.
[18:01:33.296] [Core] [INFO] [star.star_manager:1062]: Loading plugin builtin_commands ...
[18:01:33.306] [Core] [INFO] [star.star_manager:1146]: Plugin builtin_commands (0.0.1) by Soulter: AstrBot's internal plugin, providing all built-in commands such as /reset.
[18:01:33.306] [Core] [INFO] [star.star_manager:1062]: Loading plugin astrbot ...
[18:01:33.311] [Core] [INFO] [star.star_manager:1146]: Plugin astrbot (4.1.0) by AstrBot Team: AstrBot's internal plugin, providing some basic capabilities.
[18:01:33.317] [Core] [INFO] [provider.manager:590]: Loading model openai_chat_completion(siliconflow/nex-agi/Nex-N2-Pro) ...
[18:01:33.349] [Core] [DBUG] [provider.register:50]: Model provider registered: openai_chat_completion
[18:01:33.718] [Core] [INFO] [provider.manager:696]: Selected openai_chat_completion(siliconflow/nex-agi/Nex-N2-Pro) as default chat model provider
[18:01:33.718] [Core] [INFO] [provider.manager:590]: Loading model openai_chat_completion(tokeness/tokeness/free) ...
[18:01:33.718] [Core] [INFO] [provider.manager:590]: Loading model openai_chat_completion(siliconflow/Qwen/Qwen3.5-4B) ...
[18:01:33.719] [Core] [INFO] [provider.manager:590]: Loading model zhipu_chat_completion(zhipu/glm-4.6v-flash) ...
[18:01:33.719] [Core] [DBUG] [provider.register:50]: Model provider registered: zhipu_chat_completion
[18:01:33.723] [Core] [INFO] [provider.func_tool_manager:590]: 等待 1 个 MCP 服务初始化...
[18:01:33.756] [Core] [INFO] [knowledge_base.kb_mgr:62]: KnowledgeBase database initialized: /mnt/drive-d/code/deploy/astrbot/data/knowledge_base/kb.db
[18:01:33.993] [Core] [INFO] [platform.manager:125]: Loading IM platform adapter qq_official(default) ...
[18:01:34.010] [Core] [DBUG] [platform.register:60]: Platform adapter registered: qq_official
[18:01:34.011] [Core] [INFO] [dashboard.server:205]: Using bundled dashboard dist: /home/brick/.local/share/uv/tools/astrbot/lib/python3.12/site-packages/astrbot/dashboard/dist
[18:01:34.311] [Core] [INFO] [dashboard.server:581]: Starting WebUI at http://0.0.0.0:6185
[18:01:34.311] [Core] [INFO] [dashboard.server:583]: WebUI listens on all interfaces. Check security. Set dashboard.host in data/cmd_config.json to change it.
[18:01:34.311] [Core] [INFO] [dashboard.server:626]: 
 ✨✨✨
  AstrBot v4.26.2 WebUI is ready

   ➜  Local: http://localhost:6185
   ➜  Network: http://127.0.0.1:6185
   ➜  Network: http://192.168.5.72:6185
   ➜  Network: http://172.17.0.1:6185
   ➜  Username: astrbot
 ✨✨✨

[18:01:34.312] [Core] [INFO] [core.core_lifecycle:341]: AstrBot started.
[18:01:34.316] [Core] [INFO] [utils.temp_dir_cleaner:127]: TempDirCleaner started. interval=600s cleanup_ratio=0.3
[2026-06-28 18:01:34 +0800] [48063] [INFO] Running on http://0.0.0.0:6185 (CTRL + C to quit)
[18:01:34.541] [Core] [INFO] [t2i.network_strategy:131]: Successfully got 2 official T2I endpoints.
[18:01:35.047] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] 
[18:01:35.047] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] 
[18:01:35.047] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] ╭──────────────────────────────────────────────────────────────────────────────╮
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                                                                              │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                                                                              │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                         ▄▀▀ ▄▀█ █▀▀ ▀█▀ █▀▄▀█ █▀▀ █▀█                        │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                         █▀  █▀█ ▄▄█  █  █ ▀ █ █▄▄ █▀▀                        │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                                                                              │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                                                                              │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                                                                              │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                                FastMCP 3.4.2                                 │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                            https://gofastmcp.com                             │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                                                                              │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │         🖥  Server:      PaddleOCR PaddleOCR-VL-1.6 MCP server, 3.4.2         │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │         🚀 Deploy free: https://horizon.prefect.io                           │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] │                                                                              │
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] ╰──────────────────────────────────────────────────────────────────────────────╯
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] 
[18:01:35.048] [Core] [INFO] [utils.log_pipe:31]: [MCPServer-paddleocr] 
[18:01:35.055] [Core] [DBUG] [provider.func_tool_manager:784]: MCP server paddleocr list tools response: meta=None nextCursor=None tools=[Tool(name='paddleocr_vl', title=None, description='PaddleOCR paddleocr_vl tool. Inference provider: aistudio (AI Studio). Supported input_data: absolute file path accessible to the MCP server process (~ is expanded), HTTP(S) URL, raw Base64, or data URL. Relative paths are rejected. Backend-specific conversion is handled by the MCP server. Optional runtime_params keys: format_block_content, layout_merge_bboxes_mode, layout_nms, layout_shape_mode, layout_threshold, layout_unclip_ratio, markdown_ignore_labels, max_new_tokens, max_pixels, merge_layout_blocks, min_pixels, prompt_label, repetition_penalty, temperature, top_p, use_chart_recognition, use_doc_orientation_classify, use_doc_unwarping, use_layout_detection, use_ocr_for_image_block, use_seal_recognition, vlm_extra_args.', inputSchema={'additionalProperties': False, 'properties': {'input_data': {'type': 'string', 'description': 'File input. Format depends on the configured inference\nprovider; see the tool description for supported forms.'}, 'output_mode': {'default': 'simple', 'type': 'string', 'description': '``simple`` for plain text, ``detailed`` for JSON.'}, 'file_type': {'anyOf': [{'type': 'string'}, {'type': 'null'}], 'default': None, 'description': '``image`` or ``pdf`` when required by the HTTP API.'}, 'return_images': {'default': True, 'type': 'boolean', 'description': 'Whether to include images in document parsing output.'}, 'runtime_params': {'anyOf': [{'additionalProperties': True, 'type': 'object'}, {'type': 'null'}], 'default': None, 'description': 'Optional pipeline parameters as a JSON object.'}}, 'required': ['input_data'], 'type': 'object'}, outputSchema=None, icons=None, annotations=None, meta={'fastmcp': {'tags': []}}, execution=None)]
[18:01:35.061] [Core] [INFO] [provider.func_tool_manager:803]: Connected to MCP server paddleocr, Tools: ['paddleocr_vl']
[18:01:35.062] [Core] [INFO] [provider.func_tool_manager:634]: MCP services initialization completed: 1/1 successful, 0 failed.
[18:01:35.322] [Core] [INFO] [qqofficial.qqofficial_platform_adapter:168]: [QQOfficial] Websocket session starting.
[18:01:35.793] [Core] [INFO] [utils.llm_metadata:63]: Successfully fetched metadata for 2656 LLMs.
[18:02:23.628] [Core] [DBUG] [services.plugin_service:1105]: Plugin cache: local=5c61b3b9c1f8b62d9ee833b15641e7af, remote=5c61b3b9c1f8b62d9ee833b15641e7af, effective=True
[18:02:23.653] [Core] [DBUG] [services.plugin_service:1121]: Loading cached file: /mnt/drive-d/code/deploy/astrbot/data/plugins.json, Cache time: 2026-06-28T17:47:58.893606
[18:02:23.654] [Core] [DBUG] [services.plugin_service:970]: 缓存MD5匹配,使用缓存的插件市场数据
[18:02:27.500] [Core] [INFO] [provider.func_tool_manager:690]: Received shutdown signal for MCP client paddleocr
[18:02:27.834] [Core] [DBUG] [agent.mcp_client:671]: Error closing current exit stack: Attempted to exit cancel scope in a different task than it was entered in
[18:02:27.834] [Core] [INFO] [provider.func_tool_manager:823]: Disconnected from MCP server paddleocr

核心问题可能是[Core] [DBUG] [agent.mcp_client:671]: Error closing current exit stack: Attempted to exit cancel scope in a different task than it was entered in

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • Yes!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendbugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions