fix: use fixed 5s retry on cert-not-yet-valid to avoid 70s exponential backoff before NTP sync

Made-with: Cursor
This commit is contained in:
stswangzhiping
2026-03-20 08:34:53 +08:00
parent d3bd5ca3e7
commit 108bea4ed7

View File

@@ -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 不可达
}
}
setTimeout(() => this._connect(), this._backoff);
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);
}
});
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'))
);
});
}