From 7d27f4d93a6165b31bd1b431ca049544419f00f3 Mon Sep 17 00:00:00 2001 From: biao Date: Sat, 19 Sep 2026 16:55:00 +0800 Subject: [PATCH] fix(log): make console sink non-blocking (enqueue=True) The console loguru sink wrote to sys.stdout synchronously on the event loop thread. A blocking console (Windows QuickEdit with text selected, stalled terminal, full pipe) therefore stalled the whole asyncio loop. Observed stalls of 33s/35s in event_loop_watchdog.log, which killed the websocket heartbeat and dropped the platform connection. File/trace sinks already used enqueue=True; the console sink did not. --- astrbot/core/log.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/astrbot/core/log.py b/astrbot/core/log.py index 15b50dbdd7..354901c15c 100644 --- a/astrbot/core/log.py +++ b/astrbot/core/log.py @@ -225,10 +225,15 @@ def _setup_loguru(cls) -> None: return _loguru.remove() + # NOTE(n100): enqueue=True keeps console logging OFF the event loop + # thread. Without it a blocking console (e.g. Windows QuickEdit with + # text selected) stalls the whole asyncio loop for many seconds, which + # kills the heartbeat of long-lived websocket clients. cls._console_sink_id = _loguru.add( sys.stdout, level="DEBUG", colorize=True, + enqueue=True, filter=lambda record: not record["extra"].get("is_trace", False), format=( "[{time:HH:mm:ss.SSS}] {extra[plugin_tag]} " @@ -509,6 +514,7 @@ def configure_logger( sys.stdout, level=configured_level, colorize=True, + enqueue=True, # NOTE(n100): non-blocking, see above filter=lambda record: ( not record["extra"].get("is_trace", False) ),