fix: 添加 WebSocket 重连成功日志,优化重连逻辑
This commit is contained in:
1 parent
6822e3808a
commit
b4fd7b2a59
3 files changed
+15
No files matched your search
@@ -272,6 +272,11 @@ export class FileManager {
|
||||
|
||||
socket.addEventListener('open', () => {
|
||||
if (!this.isCurrent(socket, generation)) return;
|
||||
if (this.reconnectAttempts > 0) {
|
||||
console.log(
|
||||
`[WS-Reconnect] ${new Date().toISOString()} | SFTP | reconnect_success | attempt=${this.reconnectAttempts}/${RECONNECT_MAX_ATTEMPTS}`,
|
||||
);
|
||||
}
|
||||
this.reconnectAttempts = 0;
|
||||
this.init();
|
||||
});
|
||||
|
||||
@@ -293,6 +293,11 @@ export class ProcessManager {
|
||||
this.setStatus('正在启动进程监控…', 'Starting process monitor…');
|
||||
socket.addEventListener('open', () => {
|
||||
if (!this.isCurrent(socket, generation)) return;
|
||||
if (this.reconnectAttempts > 0) {
|
||||
console.log(
|
||||
`[WS-Reconnect] ${new Date().toISOString()} | Process | reconnect_success | attempt=${this.reconnectAttempts}/${RECONNECT_MAX_ATTEMPTS}`,
|
||||
);
|
||||
}
|
||||
this.reconnectAttempts = 0;
|
||||
socket.send(JSON.stringify({ type: 'process_start' }));
|
||||
});
|
||||
|
||||
@@ -106,6 +106,11 @@ export class WebSocketReconnectManager {
|
||||
|
||||
private handleClose(event: CloseEvent): void {
|
||||
if (this.destroyed) return;
|
||||
// Guard: ignore close events from superseded sockets that have been
|
||||
// replaced by a newer attach() or a successful reconnect. Without
|
||||
// this check a stale socket closing later could trigger a spurious
|
||||
// reconnection cycle.
|
||||
if (event.target !== this.socket) return;
|
||||
|
||||
this.log({
|
||||
timestamp: new Date().toISOString(),
|
||||
|
||||
Reference in new issue
Block a user