fix(infra): cap jsonl socket timeouts · openclaw/openclaw@2860da8
steipete
·
2026-05-30
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import net from "node:net"; |
2 | 2 | import path from "node:path"; |
3 | 3 | import { describe, expect, it } from "vitest"; |
| 4 | +import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js"; |
4 | 5 | import { withTempDir } from "../test-helpers/temp-dir.js"; |
5 | | -import { requestJsonlSocket } from "./jsonl-socket.js"; |
| 6 | +import { requestJsonlSocket, testApi } from "./jsonl-socket.js"; |
6 | 7 | |
7 | 8 | async function listenOnSocket(server: net.Server, socketPath: string): Promise<boolean> { |
8 | 9 | try { |
@@ -26,6 +27,10 @@ function acceptDoneValue(msg: unknown): number | null | undefined {
|
26 | 27 | } |
27 | 28 | |
28 | 29 | describe.runIf(process.platform !== "win32")("requestJsonlSocket", () => { |
| 30 | +it("caps oversized socket timeouts before arming the watchdog", () => { |
| 31 | +expect(testApi.resolveJsonlSocketTimeoutMs(Number.MAX_SAFE_INTEGER)).toBe(MAX_TIMER_TIMEOUT_MS); |
| 32 | +}); |
| 33 | + |
29 | 34 | it("ignores malformed and non-accepted lines until one is accepted", async () => { |
30 | 35 | await withTempDir({ prefix: "openclaw-jsonl-socket-" }, async (dir) => { |
31 | 36 | const socketPath = path.join(dir, "socket.sock"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import net from "node:net"; |
2 | 2 | import { clearTimeout as clearNodeTimeout, setTimeout as setNodeTimeout } from "node:timers"; |
| 3 | +import { resolveTimerTimeoutMs } from "../shared/number-coercion.js"; |
3 | 4 | |
4 | 5 | /** |
5 | 6 | * Sends one JSONL request line, half-closes the write side, and waits for an accepted response line. |
6 | 7 | */ |
| 8 | +function resolveJsonlSocketTimeoutMs(timeoutMs: number): number { |
| 9 | +return resolveTimerTimeoutMs(timeoutMs, 1); |
| 10 | +} |
| 11 | + |
7 | 12 | export async function requestJsonlSocket<T>(params: { |
8 | 13 | socketPath: string; |
9 | 14 | requestLine: string; |
10 | 15 | timeoutMs: number; |
11 | 16 | accept: (msg: unknown) => T | null | undefined; |
12 | 17 | }): Promise<T | null> { |
13 | | -const { socketPath, requestLine, timeoutMs, accept } = params; |
| 18 | +const { socketPath, requestLine, accept } = params; |
| 19 | +const timeoutMs = resolveJsonlSocketTimeoutMs(params.timeoutMs); |
14 | 20 | return await new Promise((resolve) => { |
15 | 21 | const client = new net.Socket(); |
16 | 22 | let settled = false; |
@@ -63,3 +69,6 @@ export async function requestJsonlSocket<T>(params: {
|
63 | 69 | }); |
64 | 70 | }); |
65 | 71 | } |
| 72 | + |
| 73 | +export const testApi = { resolveJsonlSocketTimeoutMs }; |
| 74 | +export { testApi as __test__ }; |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。