Skip to content

[Bug] weixin_oc 的 getupdates 长轮询超时后会导致适配器退出 #6901

@superjackche

Description

@superjackche

What happened / 发生了什么

我这边在使用 weixin_oc(个人微信)时,发现一个长轮询超时问题。

现象是:个人微信登录成功后,AstrBot 会正常进入入站消息轮询;但运行一段时间后,ilink/bot/getupdates 这条长轮询请求会偶发 TimeoutError。当前这个异常会一路冒泡到 run(),然后直接出现:

  • weixin_oc(...): run failed

一旦出现这条报错,对应的 weixin_oc 适配器就不再继续轮询消息了,通常只能靠重启进程或重新拉起适配器恢复。

这个问题发生在“登录成功后的入站消息轮询阶段”,不是二维码登录轮询阶段。

我期望的行为是:

  • 长轮询超时应该被当成正常边界情况,或者至少是可恢复异常
  • 发生超时后继续下一轮轮询,而不是直接退出适配器主循环

实际行为是:

  • getupdates 超时后直接 run failed
  • 适配器退出,不再继续收消息

Reproduce / 如何复现?

  1. 使用 AstrBot v4.22.0 配置并启用 weixin_oc
  2. 完成二维码登录,确保个人微信已经成功接入
  3. 保持 AstrBot 正常运行
  4. 等待一段时间,让 getupdates 长轮询持续工作
  5. 一段时间后会看到 TimeoutError
  6. 随后日志里出现 weixin_oc(...): run failed
  7. 对应适配器停止轮询,直到手动重启

我本地的相关配置如下:

  • weixin_oc_qr_poll_interval = 1
  • weixin_oc_long_poll_timeout_ms = 35000
  • weixin_oc_api_timeout_ms = 15000

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

  • AstrBot version: v4.22.0
  • Deployment method: macOS 本地部署,使用 astrbot run 启动,并通过 launchd 常驻
  • Python version: 3.13.12
  • Provider used: openai_local/gpt-5.4
  • Messaging platform used: weixin_oc

补充一下:这个问题看起来和 provider 本身没关系,报错栈是在 weixin_oc 的平台轮询路径里触发的。

OS

macOS

Logs / 报错日志

[2026-03-24 05:02:47.594] [Core] [ERRO] [v4.22.0] [weixin_oc.weixin_oc_adapter:902]: weixin_oc(weixin_main): run failed:
Traceback (most recent call last):
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/aiohttp/client_reqrep.py", line 539, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
                       ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/aiohttp/streams.py", line 703, in read
    await self._waiter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py", line 898, in run
    await self._poll_inbound_updates()
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py", line 737, in _poll_inbound_updates
    data = await self.client.request_json(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<10 lines>...
    )
    ^
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/astrbot/core/platform/sources/weixin_oc/weixin_oc_client.py", line 215, in request_json
    async with self._http_session.request(
               ~~~~~~~~~~~~~~~~~~~~~~~~~~^
        method,
        ^^^^^^^
    ...<4 lines>...
        timeout=timeout,
        ^^^^^^^^^^^^^^^^
    ) as resp:
    ^
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/aiohttp/client.py", line 1510, in __aenter__
    self._resp: _RetType = await self._coro
                           ^^^^^^^^^^^^^^^^
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/aiohttp/client.py", line 779, in _request
    resp = await handler(req)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/aiohttp/client.py", line 757, in _connect_and_send_request
    await resp.start(conn)
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/aiohttp/client_reqrep.py", line 534, in start
    with self._timer:
         ^^^^^^^^^^^
  File "/Users/jack/.local/share/uv/tools/astrbot/lib/python3.13/site-packages/aiohttp/helpers.py", line 713, in __exit__
    raise asyncio.TimeoutError from exc_val
TimeoutError


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

- [x] Yes!

### Code of Conduct

- [x] I have read and agree to abide by the project's [Code of Conduct](https://docs.github.com/zh/site-policy/github-terms/github-community-code-of-conduct)。

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:platformThe bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on.bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions