From 7f008d1f9c17e9a3f2245ef6ae00127909688f92 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Sat, 4 Mar 2023 13:22:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=87=AA=E5=8A=A8=E9=87=8D?= =?UTF-8?q?=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/modules/sync/client/client.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/modules/sync/client/client.ts b/src/main/modules/sync/client/client.ts index ea0bff2a..f53bb105 100644 --- a/src/main/modules/sync/client/client.ts +++ b/src/main/modules/sync/client/client.ts @@ -38,12 +38,13 @@ const handleConnection = (socket: LX.Sync.Client.Socket) => { const heartbeatTools = { failedNum: 0, - maxTryNum: 3, + maxTryNum: 100000, + stepMs: 3000, pingTimeout: null as NodeJS.Timeout | null, delayRetryTimeout: null as NodeJS.Timeout | null, handleOpen() { console.log('open') - this.failedNum = 0 + // this.failedNum = 0 this.heartbeat() }, heartbeat() { @@ -70,16 +71,23 @@ const heartbeatTools = { throw new Error('connect error') } + const waitTime = Math.min(2000 + Math.floor(this.failedNum / 2) * this.stepMs, 15000) + + // sendSyncStatus({ + // status: false, + // message: `Waiting ${waitTime / 1000}s reconnnect...`, + // }) + this.delayRetryTimeout = setTimeout(() => { this.delayRetryTimeout = null if (!client) return console.log(dateFormat(new Date()), 'reconnnect...') sendSyncStatus({ status: false, - message: `Try reconnnect... (${this.failedNum}/${this.maxTryNum})`, + message: `Try reconnnect... (${this.failedNum})`, }) connect(client.data.urlInfo, client.data.keyInfo) - }, 2000) + }, waitTime) }, clearTimeout() { if (this.delayRetryTimeout) { @@ -177,6 +185,7 @@ export const connect = (urlInfo: LX.Sync.Client.UrlInfo, keyInfo: LX.Sync.Client handleConnection(client as LX.Sync.Client.Socket) log.info('register list sync service success') client!.isReady = true + heartbeatTools.failedNum = 0 sendSyncStatus({ status: true, message: '',