From cb090fe8e0f5b9d4709f0a5981e23386e5530b64 Mon Sep 17 00:00:00 2001 From: kicer Date: Thu, 24 Sep 2026 17:04:55 +0800 Subject: [PATCH] =?UTF-8?q?video=5Ftask:=20=E4=B8=8A=E6=B8=B8=20submit/que?= =?UTF-8?q?ry=20=E5=8A=A0=2030s=20=E8=B6=85=E6=97=B6=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E4=B8=8A=E6=B8=B8=E6=8C=82=E8=80=8C=E4=B8=8D=E5=9B=9E?= =?UTF-8?q?=E6=97=B6=E6=8B=96=E6=AD=BB=E5=B7=A5=E5=85=B7=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mcp/video_task/README.md | 1 + mcp/video_task/src/mcp-server.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/mcp/video_task/README.md b/mcp/video_task/README.md index 083ba66..4936baf 100644 --- a/mcp/video_task/README.md +++ b/mcp/video_task/README.md @@ -149,6 +149,7 @@ Token 仅在每次 tool call 时从 header 读取,不写入任何存储、不 | initialize 时缺 token | `401` | JSON-RPC `error.message` 提示补充 header | | 智谱 API 4xx/5xx | `200`(MCP 工具返回) | `isError: true`,正文含智谱返回的状态码和 body | | 网络失败 | `200`(MCP 工具返回) | `isError: true`,正文含 `fetch` 错误信息 | +| 上游挂住不回(超时 >30s) | `200`(MCP 工具返回) | `isError: true`,正文提示 timed out;`fetch` 带 `AbortSignal.timeout`,不会无限卡住工具调用 | --- diff --git a/mcp/video_task/src/mcp-server.js b/mcp/video_task/src/mcp-server.js index 88a82a2..92a9467 100644 --- a/mcp/video_task/src/mcp-server.js +++ b/mcp/video_task/src/mcp-server.js @@ -19,6 +19,9 @@ const DEFAULT_QUALITY = "speed"; // speed | quality const DEFAULT_FPS = 30; // 30 | 60 const DEFAULT_WATERMARK_ENABLED = true; // 平台政策默认 true +// submit/query 都是快接口,卡住基本等于上游挂了;限时避免工具调用被拖死 +const UPSTREAM_TIMEOUT_MS = 30_000; + // ── 优雅退出 ────────────────────────────────────────────────────────────── // 容器里 node 以 PID 1 运行且未注册 SIGTERM 处理器时,内核不会对其执行默认 // 终止动作,docker stop/restart 会白等满 10s 宽限期才被 SIGKILL。 @@ -119,9 +122,19 @@ async function callZhipu({ url, token, method = "POST", body }) { Authorization: `Bearer ${token}`, "Content-Type": "application/json", }, + signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS), }; if (body !== undefined) init.body = JSON.stringify(body); - const resp = await fetch(url, init); + let resp; + try { + resp = await fetch(url, init); + } catch (e) { + // AbortSignal.timeout 中止时抛 TimeoutError/AbortError,转成明确的超时错误 + if (e?.name === "TimeoutError" || e?.name === "AbortError") { + throw new Error(`Upstream request timed out after ${UPSTREAM_TIMEOUT_MS} ms`); + } + throw e; + } const text = await resp.text(); let data; try {