From effd78807ed9220a5228b971f29e7df85263c5ce Mon Sep 17 00:00:00 2001 From: OG T Date: Sun, 12 Apr 2026 16:13:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(heartbeat):=20blocking=5Ftimeout=205?= =?UTF-8?q?=E2=86=920=EF=BC=8C=E5=A4=9A=20replica=20=E4=B8=8D=E6=8E=92?= =?UTF-8?q?=E9=9A=8A=E7=AD=89=E9=8E=96=E9=81=BF=E5=85=8D=E9=87=8D=E8=A4=87?= =?UTF-8?q?=E7=99=BC=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 3 個 replica 各自跑 loop,blocking_timeout=5.0 導致鎖釋放後 其他 replica 依序拿鎖,每次心跳最多發 3 條。 改為 blocking_timeout=0:拿不到鎖立刻跳過,同週期只發一條。 2026-04-12 ogt Co-Authored-By: Claude Sonnet 4.6 --- apps/api/src/services/telegram_gateway.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/api/src/services/telegram_gateway.py b/apps/api/src/services/telegram_gateway.py index 7865f547..1f8d8185 100644 --- a/apps/api/src/services/telegram_gateway.py +++ b/apps/api/src/services/telegram_gateway.py @@ -4674,8 +4674,9 @@ class TelegramGateway: # 分散式鎖:同一心跳週期只有一個 replica 發報告 # timeout=25*60 確保下一次心跳前鎖一定釋放(心跳間隔 30min) + # blocking_timeout=0: 鎖被佔用時立刻跳過,不排隊等待(避免多 replica 輪流發) try: - async with RedisLock("heartbeat:leader", timeout=25 * 60, blocking_timeout=5.0): + async with RedisLock("heartbeat:leader", timeout=25 * 60, blocking_timeout=0): report = await HeartbeatReportService().collect() text = report_to_telegram_html(report)