缺陷 / 高 / 工具系统
electron/harness/tools/registry.ts
ToolRegistry 使用 Promise.race([tool.execute(), timeout]) 实现超时控制。 超时触发后,timeout Promise resolve,但原 tool.execute() Promise 仍在后台运行,无法取消:
Promise.race([tool.execute(), timeout])
tool.execute()
Tool.execute
async executeWithTimeout(tool, input, timeoutMs) { const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeoutMs); try { return await Promise.race([ tool.execute(input, { signal: controller.signal }), new Promise((_, reject) => controller.signal.addEventListener('abort', () => reject(new Error('Tool timeout')) ) ), ]); } finally { clearTimeout(timer); } }
signal.aborted
文件: electron/harness/tools/registry.ts
修复: 引入 AbortController,超时触发 controller.abort(),通过类型断言将 signal 附加到 context 传给 tool.execute()。支持 signal 的工具可据此中止后台耗时操作,防止 Promise 未取消导致的资源泄漏。
AbortController
controller.abort()
signal
context
验证: tsc --noEmit 类型检查通过。
tsc --noEmit
No dependencies set.
The note is not visible to the blocked user.
问题类型
缺陷 / 高 / 工具系统
文件位置
electron/harness/tools/registry.ts问题描述
ToolRegistry 使用
Promise.race([tool.execute(), timeout])实现超时控制。超时触发后,timeout Promise resolve,但原
tool.execute()Promise 仍在后台运行,无法取消:影响
建议修复
Tool.execute签名中传入 AbortSignalsignal.aborted修复说明
文件:
electron/harness/tools/registry.ts修复: 引入
AbortController,超时触发controller.abort(),通过类型断言将signal附加到context传给tool.execute()。支持 signal 的工具可据此中止后台耗时操作,防止 Promise 未取消导致的资源泄漏。验证:
tsc --noEmit类型检查通过。