From 108bea4ed792caed37e5d3da88886022a5766c57 Mon Sep 17 00:00:00 2001 From: stswangzhiping <59632378+stswangzhiping@users.noreply.github.com> Date: Fri, 20 Mar 2026 08:34:53 +0800 Subject: [PATCH] fix: use fixed 5s retry on cert-not-yet-valid to avoid 70s exponential backoff before NTP sync Made-with: Cursor --- lib/client.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/client.js b/lib/client.js index ea7e636..f1e6d84 100644 --- a/lib/client.js +++ b/lib/client.js @@ -47,6 +47,8 @@ class ClawClient { this._wsFailCount = 0; // 是否曾经成功连接过(首次成功前不显示 Err0/AP) this._hasEverConnected = false; + // 最近一次 WS 错误是否是证书时间问题(NTP 未同步) + this._certTimeError = false; // systemd watchdog this._sdTimer = null; @@ -187,13 +189,25 @@ class ClawClient { led.display.showErr0(); // STA 模式 + 有网 但 VPS 不可达 } } + if (this._certTimeError) { + // NTP 未同步:固定 5s 重试,等时钟校正 + this._certTimeError = false; + this._backoff = 5_000; + log.warn('clawd', '证书时间错误(NTP 未同步),5s 后重试...'); + } else { + this._backoff = Math.min(this._backoff * 2, MAX_BACKOFF_MS); + } setTimeout(() => this._connect(), this._backoff); - this._backoff = Math.min(this._backoff * 2, MAX_BACKOFF_MS); } }); ws.on('error', (err) => { log.error('clawd', '连接错误:', err.message); + // 证书时间错误:NTP 未同步,close 后用固定短间隔重试,不做指数退避 + this._certTimeError = !!( + err.code === 'CERT_NOT_YET_VALID' || + (err.message && err.message.includes('not yet valid')) + ); }); }