From 033735d476d88ad351376467f5c715419c9a1a0f Mon Sep 17 00:00:00 2001 From: shenmo Date: Sun, 29 Mar 2026 12:06:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E4=B8=8B=E8=BD=BD):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=87=8D=E8=AF=95=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=80=92=E5=A2=9E=E8=B6=85=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将固定30秒超时改为递增超时机制(3秒/5秒/15秒) 缩短进度检查间隔至1秒,提高响应速度 --- electron/main/backend/install-manager.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/electron/main/backend/install-manager.ts b/electron/main/backend/install-manager.ts index dff27117..7839c87a 100644 --- a/electron/main/backend/install-manager.ts +++ b/electron/main/backend/install-manager.ts @@ -407,12 +407,14 @@ async function processNextInQueue() { sendStatus("downloading"); - // 下载重试逻辑:卡在0% 30秒则重启,最多3次 - const maxRetries = 3; + // 下载重试逻辑:每次超时时间递增,最多3次 + const timeoutList = [3000, 5000, 15000]; // 第一次3秒,第二次5秒,第三次15秒 let retryCount = 0; let downloadSuccess = false; - while (retryCount < maxRetries && !downloadSuccess) { + while (retryCount < timeoutList.length && !downloadSuccess) { + const currentTimeout = timeoutList[retryCount]; + if (retryCount > 0) { sendLog(`第 ${retryCount} 次重试下载...`); webContents?.send("install-progress", { id, progress: 0 }); @@ -437,8 +439,7 @@ async function processNextInQueue() { let lastProgressTime = Date.now(); let lastProgress = 0; - const zeroProgressTimeout = 30000; // 0%卡死30秒超时 - const progressCheckInterval = 3000; // 每3秒检查一次 + const progressCheckInterval = 1000; // 每1秒检查一次 // 设置超时检测定时器 const timeoutChecker = setInterval(() => { @@ -446,12 +447,12 @@ async function processNextInQueue() { // 只在进度为0时检查超时 if ( lastProgress === 0 && - now - lastProgressTime > zeroProgressTimeout + now - lastProgressTime > currentTimeout ) { clearInterval(timeoutChecker); child.kill(); reject( - new Error(`下载卡在0%超过 ${zeroProgressTimeout / 1000} 秒`), + new Error(`下载卡在0%超过 ${currentTimeout / 1000} 秒`), ); } }, progressCheckInterval); @@ -492,10 +493,10 @@ async function processNextInQueue() { downloadSuccess = true; } catch (err) { retryCount++; - if (retryCount >= maxRetries) { - throw new Error(`下载失败,已重试 ${maxRetries} 次: ${err}`); + if (retryCount >= timeoutList.length) { + throw new Error(`下载失败,已重试 ${timeoutList.length} 次: ${err}`); } - sendLog(`下载失败,准备重试 (${retryCount}/${maxRetries})`); + sendLog(`下载失败,准备重试 (${retryCount}/${timeoutList.length})`); // 等待2秒后重试 await new Promise((r) => setTimeout(r, 2000)); }