[Bug] 同步控制台日志在 stdout 受阻时阻塞主事件循环,导致整个 WebUI 无响应

Aperta
#10,898 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
22/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

The stall is in the logging path: astrbot/core/log.py (the emit method that forwards stdlib logging records to loguru) and the loguru stream sink it writes to. Start by reading how the stdout sink is configured, then reproduce by blocking stdout on Windows while the WebChat page makes requests. Done would mean logging cannot block the event loop when stdout stalls, for example by making the sink non-blocking or queued, with a test that simulates a slow stream.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
问题描述

在 Windows 本地运行 AstrBot,使用 WebChat 测试期间,整个 Dashboard 出现无响应。刷新页面或打开其他页面均无法恢复。
排查时发现,后端也无法响应独立 HTTP 请求:

GET /                     → TimeoutError,约 4 秒
GET /api/stat/start-time   → TimeoutError,约 4 秒

watchdog 捕获到的主线程栈停在:

logger.info(...)
→ logging.Handler.emit
→ Loguru
→ StreamSink.write
→ self._stream.write(message)

其中一次阻塞发生在插件接口的入口日志处,尚未进入接口主体。

目前确认的是:标准输出写入阻塞会同步阻塞调用日志的主事件循环。 实际运行中 stdout 为何受阻,不知道。

如何复现?
  1. 在 Windows 本地启动 AstrBot,打开 Dashboard。
  2. 使用 WebChat 测试,期间出现整个面板无响应。
  3. 从独立进程请求首页和状态接口,均超时。
  4. 查看 data/logs/event_loop_watchdog.log,主线程停在 Loguru 的标准输出写入处。
AstrBot 版本

v4.29.3,Python 3.12.14

操作系统

Windows

部署方式

本地源码部署,Python 虚拟环境,通过 PowerShell 启动 python main.py

使用的消息平台适配器

WebChat

错误日志
Event loop stalled for 34.985s

Thread 12084 "MainThread"
  ...
  File ".../astrbot_plugin_meme_manager/mixins/web_api.py",
       line 567, in logged_handler
    logger.info(f"{WEBUI_LOG_PREFIX} {request.method} {route_path} 开始")
  ...
  File ".../astrbot/core/log.py", line 235, in emit
    _loguru.bind(**payload).opt(exception=record.exc_info).log(
  File ".../loguru/_logger.py", line 2103, in log
    __self._log(__level, False, __self._options, __message, args, kwargs)
  File ".../loguru/_logger.py", line 2066, in _log
    handler.emit(log_record, level_id, from_decorator, raw, colored_message)
  File ".../loguru/_handler.py", line 206, in emit
    self._sink.write(str_record)
  File ".../loguru/_simple_sinks.py", line 16, in write
    self._stream.write(message)
辅助信息

event_loop_watchdog.log

检查清单
  • 我已在 Issue 列表中搜索过相关问题仍无法解决,或该问题从未被报告过。
  • 我已尝试过禁用所有插件,排除了可能是因插件导致的问题。
  • 我报告的问题与 AstrBot 本体相关,而非在报告某一插件的问题。
  • 我已阅读并同意本项目的贡献者行为准则。
  • (可选)我愿意提交 PR 以帮助修复该问题。
Lingua principale
Python
Stelle
46.4k
Fork
3.4k
Merge medio
1g 11h
PR unite (30g)
120

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di AstrBotDevs/AstrBot

Tutte le issue di AstrBotDevs/AstrBot

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.