






















@@ -34,6 +34,7 @@ const DEFAULT_FETCH_BODY_MAX_BYTES = 1024 * 1024;
3434const DEFAULT_MAX_RSS_MIB = 2048;
3535const DEFAULT_MAX_COMMAND_RSS_MIB = 8192;
3636const DEFAULT_OUTPUT_CAPTURE_CHARS = 1024 * 1024;
37+export const MAX_KITCHEN_SINK_TIMER_TIMEOUT_MS = 2_147_000_000;
3738const GATEWAY_TEARDOWN_GRACE_MS = 10000;
3839const GATEWAY_TEARDOWN_KILL_GRACE_MS = 2000;
3940const COMMAND_PARENT_SIGNAL_KILL_GRACE_MS = 2000;
@@ -149,8 +150,19 @@ export function readPositiveInt(raw, fallback, label = "value") {
149150return parsed;
150151}
151152153+export function clampKitchenSinkTimerTimeoutMs(value) {
154+if (!Number.isFinite(value)) {
155+return 1;
156+}
157+return Math.min(Math.max(1, Math.floor(value)), MAX_KITCHEN_SINK_TIMER_TIMEOUT_MS);
158+}
159+160+export function readPositiveTimerMs(raw, fallback, label = "value") {
161+return clampKitchenSinkTimerTimeoutMs(readPositiveInt(raw, fallback, label));
162+}
163+152164export function resolveKitchenSinkRpcConfig(env = process.env) {
153-const commandTimeoutMs = readPositiveInt(
165+const commandTimeoutMs = readPositiveTimerMs(
154166env.OPENCLAW_KITCHEN_SINK_RPC_COMMAND_MS,
155167DEFAULT_COMMAND_TIMEOUT_MS,
156168"OPENCLAW_KITCHEN_SINK_RPC_COMMAND_MS",
@@ -167,12 +179,12 @@ export function resolveKitchenSinkRpcConfig(env = process.env) {
167179DEFAULT_FETCH_BODY_MAX_BYTES,
168180"OPENCLAW_KITCHEN_SINK_RPC_FETCH_BODY_BYTES",
169181),
170-fetchTimeoutMs: readPositiveInt(
182+fetchTimeoutMs: readPositiveTimerMs(
171183env.OPENCLAW_KITCHEN_SINK_RPC_FETCH_MS,
172184DEFAULT_FETCH_TIMEOUT_MS,
173185"OPENCLAW_KITCHEN_SINK_RPC_FETCH_MS",
174186),
175-installTimeoutMs: readPositiveInt(
187+installTimeoutMs: readPositiveTimerMs(
176188env.OPENCLAW_KITCHEN_SINK_RPC_INSTALL_MS,
177189Math.max(commandTimeoutMs, DEFAULT_INSTALL_TIMEOUT_MS),
178190"OPENCLAW_KITCHEN_SINK_RPC_INSTALL_MS",
@@ -187,12 +199,12 @@ export function resolveKitchenSinkRpcConfig(env = process.env) {
187199DEFAULT_OUTPUT_CAPTURE_CHARS,
188200"OPENCLAW_KITCHEN_SINK_OUTPUT_CAPTURE_CHARS",
189201),
190-readyTimeoutMs: readPositiveInt(
202+readyTimeoutMs: readPositiveTimerMs(
191203env.OPENCLAW_KITCHEN_SINK_RPC_READY_MS,
192204DEFAULT_READY_TIMEOUT_MS,
193205"OPENCLAW_KITCHEN_SINK_RPC_READY_MS",
194206),
195-rpcTimeoutMs: readPositiveInt(
207+rpcTimeoutMs: readPositiveTimerMs(
196208env.OPENCLAW_KITCHEN_SINK_RPC_CALL_MS,
197209DEFAULT_RPC_TIMEOUT_MS,
198210"OPENCLAW_KITCHEN_SINK_RPC_CALL_MS",
@@ -360,6 +372,8 @@ export function runCommand(command, args, options = {}) {
360372 timeoutMs = config.commandTimeoutMs,
361373 ...spawnOptions
362374} = options;
375+const resolvedTimeoutMs = clampKitchenSinkTimerTimeoutMs(timeoutMs);
376+const resolvedTimeoutKillGraceMs = clampKitchenSinkTimerTimeoutMs(timeoutKillGraceMs);
363377const child = childProcess.spawn(command, args, {
364378stdio: ["ignore", "pipe", "pipe"],
365379 ...spawnOptions,
@@ -426,10 +440,13 @@ export function runCommand(command, args, options = {}) {
426440const timer = setTimeout(() => {
427441timedOut = true;
428442signalProcessGroup(child, "SIGTERM");
429-forceKillAt = Date.now() + timeoutKillGraceMs;
430-forceKillTimer = setTimeout(() => signalProcessGroup(child, "SIGKILL"), timeoutKillGraceMs);
443+forceKillAt = Date.now() + resolvedTimeoutKillGraceMs;
444+forceKillTimer = setTimeout(
445+() => signalProcessGroup(child, "SIGKILL"),
446+resolvedTimeoutKillGraceMs,
447+);
431448forceKillTimer.unref();
432-}, timeoutMs);
449+}, resolvedTimeoutMs);
433450child.stdout?.on("data", (chunk) => {
434451stdout = appendBoundedOutput(stdout, chunk, outputCaptureChars);
435452});
@@ -473,7 +490,7 @@ export function runCommand(command, args, options = {}) {
473490.join("\n")
474491.trim();
475492const failure = timedOut
476- ? `timed out after ${timeoutMs}ms`
493+ ? `timed out after ${resolvedTimeoutMs}ms`
477494 : `failed with ${signal || status}`;
478495reject(
479496Object.assign(
@@ -494,7 +511,7 @@ export function runCommand(command, args, options = {}) {
494511if (timedOut) {
495512void finishTimedOutCommandProcessTree(child, {
496513 forceKillAt,
497- timeoutKillGraceMs,
514+timeoutKillGraceMs: resolvedTimeoutKillGraceMs,
498515}).then(finish, finish);
499516return;
500517}
@@ -952,7 +969,7 @@ export function createRpcCliRunOptions(method, options = {}) {
952969return {
953970 ...options.commandResourceOptions,
954971resourceLabel: `gateway call ${method}`,
955-timeoutMs: config.rpcTimeoutMs + 30000,
972+timeoutMs: clampKitchenSinkTimerTimeoutMs(config.rpcTimeoutMs + 30000),
956973};
957974}
958975@@ -1034,7 +1051,7 @@ function isRetryableTransientNetworkError(error, seen = new Set()) {
10341051export async function fetchJson(url, options = {}) {
10351052const config = resolveKitchenSinkRpcConfig();
10361053const attempts = Math.max(1, options.attempts ?? 3);
1037-const timeoutMs = Math.max(1, options.timeoutMs ?? config.fetchTimeoutMs);
1054+const timeoutMs = clampKitchenSinkTimerTimeoutMs(options.timeoutMs ?? config.fetchTimeoutMs);
10381055const maxBodyBytes = Math.max(1, options.maxBodyBytes ?? config.fetchBodyMaxBytes);
10391056const externalSignal = options.signal;
10401057let lastError;
@@ -1434,7 +1451,7 @@ export async function waitForGatewayReady(child, port, logPath, options = {}) {
14341451const config = resolveKitchenSinkRpcConfig();
14351452const started = Date.now();
14361453let lastError = "";
1437-const timeoutMs = Math.max(1, options.timeoutMs ?? config.readyTimeoutMs);
1454+const timeoutMs = clampKitchenSinkTimerTimeoutMs(options.timeoutMs ?? config.readyTimeoutMs);
14381455const pollDelayMs = Math.max(1, options.pollDelayMs ?? 250);
14391456const logReportedReady = createGatewayReadyLogScanner(logPath);
14401457const childExit = createChildExitPromise(child);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。