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')) + ); }); }