Skip to content

[v1.4] 新增批次检查脚本的 timeout, 避免一个脚本更新时间太长导致所有脚本检查失败#1265

Merged
CodFrm merged 3 commits intoscriptscat:release/v1.4from
cyfung1031:pr-timeout-update-301
Mar 16, 2026
Merged

[v1.4] 新增批次检查脚本的 timeout, 避免一个脚本更新时间太长导致所有脚本检查失败#1265
CodFrm merged 3 commits intoscriptscat:release/v1.4from
cyfung1031:pr-timeout-update-301

Conversation

@cyfung1031
Copy link
Collaborator

@cyfung1031 cyfung1031 commented Feb 18, 2026

更新时间超过 5分钟会被视为更新检查失败,直接跳过显示
这种脚本必须在手动更新那边

不加的话,一个导致其他脚本的更新都不显示了

@cyfung1031 cyfung1031 changed the title 新增批次检查脚本的 timeout, 避免一个脚本更新时间太长导致所有脚本检查失败 [v1.4] 新增批次检查脚本的 timeout, 避免一个脚本更新时间太长导致所有脚本检查失败 Mar 15, 2026
@cyfung1031 cyfung1031 changed the base branch from release/v1.3 to release/v1.4 March 15, 2026 05:05
@CodFrm CodFrm requested a review from Copilot March 16, 2026 07:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本次 PR 主要针对 Service Worker 侧的脚本批量更新检查流程,加入整体超时控制并调整结果收集方式,以避免更新检查长时间阻塞并保证返回结果顺序稳定。

Changes:

  • checkUpdatesAvailable 增加 5 分钟超时(Promise.race + sleep)。
  • 使用 Map 按 UUID 记录检查结果并在返回时保持顺序一致(未完成/失败默认 false)。
  • 将并行等待改为 Promise.allSettled,避免单个任务异常影响整体流程。

Comment on lines +786 to +801
await Promise.race([
sleep(300_000), // 5 minutes
Promise.allSettled(
(uuids as string[]).map(async (uuid, _idx) => {
results.set(uuid, false); // 確保次序
const script = scripts[_idx];
const res =
!script || script.uuid !== uuid || !checkScripts.includes(script)
? false
: await this._checkUpdateAvailable(script, delayFn);
if (!res) return false;
results.set(uuid, res);
return res;
})
),
]);
Comment on lines +786 to +802
await Promise.race([
sleep(300_000), // 5 minutes
Promise.allSettled(
(uuids as string[]).map(async (uuid, _idx) => {
results.set(uuid, false); // 確保次序
const script = scripts[_idx];
const res =
!script || script.uuid !== uuid || !checkScripts.includes(script)
? false
: await this._checkUpdateAvailable(script, delayFn);
if (!res) return false;
results.set(uuid, res);
return res;
})
),
]);
return [...results.values()];
sleep(300_000), // 5 minutes
Promise.allSettled(
(uuids as string[]).map(async (uuid, _idx) => {
results.set(uuid, false); // 確保次序
- fetchScriptBody 添加 AbortSignal 支持
- 繁体转简体:確保次序 → 确保顺序
- 用 setTimeout+clearTimeout 替代 sleep,超时后正确清理
- 超时时通过 AbortController 中止进行中的请求
- Map 预初始化确保返回顺序一致
@CodFrm CodFrm merged commit 40c99fb into scriptscat:release/v1.4 Mar 16, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants