Skip to content

[Bug] weixin_oc (个人微信) 在短暂断网/代理切换后退出轮询,无法自动恢复 #7022

@GowayLee

Description

@GowayLee

What happened / 发生了什么

运行 AstrBot 时,如果系统网络发生短暂中断,或者切换代理导致连接瞬时断开,weixin_oc 渠道会报错并直接退出运行。
之后即使网络已经恢复,渠道也不会自动恢复连接,只能重启 AstrBot 才能继续工作。

Reproduce / 如何复现?

复现方式

  1. 启动 AstrBot,并确保 weixin_oc 已正常登录、正常收消息
  2. 在运行过程中切换系统代理,或者让网络短暂断开
  3. 等待 weixin_oc 的长轮询请求命中这次网络波动
  4. 观察日志

期望结果

控制台出现类似下面的错误:

[Core] [ERRO] [weixin_oc.weixin_oc_adapter]: weixin_oc(个人微信): run failed: Server disconnected

Traceback ...
...

aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

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

v4.22.1
Linux本地开发环境
个人微信(weinxin_oc)适配器

OS

Linux

Logs / 报错日志

[01:10:25.900] [Core] [ERRO] [v4.22.1] [weixin_oc.weixin_oc_adapter:908]: weixin_oc(个人微信): run failed: Server disconnected
Traceback (most recent call last):

  File "/home/xxx/application-space/AstrBot/main.py", line 141, in <module>
    asyncio.run(main_async(args.webui_dir))
    │       │   │          │    └ None
    │       │   │          └ Namespace(webui_dir=None)
    │       │   └ <function main_async at 0x7ff8e9e34f40>
    │       └ <function run at 0x7ff8ecddc2c0>
    └ <module 'asyncio' from '/home/xxx/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/__init...

  File "/home/xxx/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           │      │   └ <coroutine object main_async at 0x7ff8e9e058c0>
           │      └ <function Runner.run at 0x7ff8ecc399e0>
           └ <asyncio.runners.Runner object at 0x7ff8bff2ea80>
  File "/home/xxx/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           │    │     │                  └ <Task pending name='Task-1' coro=<main_async() running at /home/xxx/application-space/AstrBot/main.py:121> wait_for=<_G...
           │    │     └ <function BaseEventLoop.run_until_complete at 0x7ff8ecc374c0>
           │    └ <_UnixSelectorEventLoop running=True closed=False debug=False>
           └ <asyncio.runners.Runner object at 0x7ff8bff2ea80>
  File "/home/xxx/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/base_events.py", line 678, in run_until_complete
    self.run_forever()
    │    └ <function BaseEventLoop.run_forever at 0x7ff8ecc37420>
    └ <_UnixSelectorEventLoop running=True closed=False debug=False>
  File "/home/xxx/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/base_events.py", line 645, in run_forever
    self._run_once()
    │    └ <function BaseEventLoop._run_once at 0x7ff8ecc39260>
    └ <_UnixSelectorEventLoop running=True closed=False debug=False>
  File "/home/xxx/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/base_events.py", line 1999, in _run_once
    handle._run()
    │      └ <function Handle._run at 0x7ff8ecd6a840>
    └ <Handle Task.task_wakeup(<Future finis...isconnected')>)>
  File "/home/xxx/.local/share/uv/python/cpython-3.12.11-linux-x86_64-gnu/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ <member '_args' of 'Handle' objects>
    │    │            │    │           └ <Handle Task.task_wakeup(<Future finis...isconnected')>)>
    │    │            │    └ <member '_callback' of 'Handle' objects>
    │    │            └ <Handle Task.task_wakeup(<Future finis...isconnected')>)>
    │    └ <member '_context' of 'Handle' objects>
    └ <Handle Task.task_wakeup(<Future finis...isconnected')>)>

> File "/home/xxx/application-space/AstrBot/astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py", line 899, in run
    await self._poll_inbound_updates()
          │    └ <function WeixinOCAdapter._poll_inbound_updates at 0x7ff8bc4a1a80>
          └ <astrbot.core.platform.sources.weixin_oc.weixin_oc_adapter.WeixinOCAdapter object at 0x7ff8bc7b8110>

  File "/home/xxx/application-space/AstrBot/astrbot/core/platform/sources/weixin_oc/weixin_oc_adapter.py", line 737, in _poll_inbound_updates
    data = await self.client.request_json(
                 │    │      └ <function WeixinOCClient.request_json at 0x7ff8bc4a0900>
                 │    └ <astrbot.core.platform.sources.weixin_oc.weixin_oc_client.WeixinOCClient object at 0x7ff8bc4583e0>
                 └ <astrbot.core.platform.sources.weixin_oc.weixin_oc_adapter.WeixinOCAdapter object at 0x7ff8bc7b8110>

  File "/home/xxx/application-space/AstrBot/astrbot/core/platform/sources/weixin_oc/weixin_oc_client.py", line 215, in request_json
    async with self._http_session.request(
               │    │             └ <function ClientSession.request at 0x7ff8ebf06ac0>
               │    └ <aiohttp.client.ClientSession object at 0x7ff8bc45be60>
               └ <astrbot.core.platform.sources.weixin_oc.weixin_oc_client.WeixinOCClient object at 0x7ff8bc4583e0>

  File "/home/xxx/application-space/AstrBot/.venv/lib/python3.12/site-packages/aiohttp/client.py", line 1510, in __aenter__
    self._resp: _RetType = await self._coro
    │    │                       │    └ <member '_coro' of '_BaseRequestContextManager' objects>
    │    │                       └ <aiohttp.client._BaseRequestContextManager object at 0x7ff8aca6cbb0>
    │    └ <member '_resp' of '_BaseRequestContextManager' objects>
    └ <aiohttp.client._BaseRequestContextManager object at 0x7ff8aca6cbb0>
  File "/home/xxx/application-space/AstrBot/.venv/lib/python3.12/site-packages/aiohttp/client.py", line 779, in _request
    resp = await handler(req)
                 │       └ <aiohttp.client_reqrep.ClientRequest object at 0x7ff8aca6fdd0>
                 └ <function ClientSession._request.<locals>._connect_and_send_request at 0x7ff8bc2d2b60>
  File "/home/xxx/application-space/AstrBot/.venv/lib/python3.12/site-packages/aiohttp/client.py", line 757, in _connect_and_send_request
    await resp.start(conn)
          │    │     └ Connection<ConnectionKey(host='ilinkai.weixin.qq.com', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_he...
          │    └ <function ClientResponse.start at 0x7ff8ec0aa0c0>
          └ <ClientResponse(https://ilinkai.weixin.qq.com/ilink/bot/getupdates) [None None]>
            None
  File "/home/xxx/application-space/AstrBot/.venv/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 539, in start
    message, payload = await protocol.read()  # type: ignore[union-attr]
                             │        └ <function DataQueue.read at 0x7ff8ec017920>
                             └ <aiohttp.client_proto.ResponseHandler object at 0x7ff8acc06750>
  File "/home/xxx/application-space/AstrBot/.venv/lib/python3.12/site-packages/aiohttp/streams.py", line 703, in read
    await self._waiter
          │    └ None
          └ <aiohttp.client_proto.ResponseHandler object at 0x7ff8acc06750>

aiohttp.client_exceptions.ServerDisconnectedError: Server disconnected

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

  • Yes!

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