惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
博客园 - 司徒正美
小众软件
小众软件
H
Help Net Security
博客园 - 聂微东
宝玉的分享
宝玉的分享
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
M
MIT News - Artificial intelligence
博客园 - 【当耐特】
U
Unit 42
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
S
SegmentFault 最新的问题
腾讯CDC
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Martin Fowler
Martin Fowler
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(test): harden gateway network ws timeout · openclaw/o...
vincentkoc · 2026-05-27 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -1,5 +1,6 @@

11

import { WebSocket } from "ws";

22

import { PROTOCOL_VERSION } from "../../../../dist/gateway/protocol/index.js";

3+

import { waitForWebSocketOpen } from "./open-websocket.mjs";

34
45

const url = process.env.GW_URL;

56

const token = process.env.GW_TOKEN;

@@ -24,20 +25,7 @@ function delay(ms) {

2425
2526

async function openSocket(timeoutMs = 10_000) {

2627

const ws = new WebSocket(url);

27-

await new Promise((resolve, reject) => {

28-

const timer = setTimeout(() => {

29-

ws.close();

30-

reject(new Error("ws open timeout"));

31-

}, timeoutMs);

32-

ws.once("open", () => {

33-

clearTimeout(timer);

34-

resolve();

35-

});

36-

ws.once("error", (error) => {

37-

clearTimeout(timer);

38-

reject(error instanceof Error ? error : new Error(String(error)));

39-

});

40-

});

28+

await waitForWebSocketOpen(ws, timeoutMs, "ws open timeout");

4129

return ws;

4230

}

4331
Original file line numberDiff line numberDiff line change

@@ -0,0 +1,41 @@

1+

export function waitForWebSocketOpen(ws, timeoutMs, message = "ws open timeout") {

2+

return new Promise((resolve, reject) => {

3+

let settled = false;

4+
5+

const settle = (fn, value) => {

6+

if (settled) {

7+

return;

8+

}

9+

settled = true;

10+

clearTimeout(timer);

11+

ws.off?.("open", onOpen);

12+

ws.off?.("error", onError);

13+

fn(value);

14+

};

15+

const onOpen = () => settle(resolve);

16+

const onError = (error) =>

17+

settle(reject, error instanceof Error ? error : new Error(String(error)));

18+

const timer = setTimeout(() => {

19+

const consumeAbortError = () => {};

20+

const removeAbortErrorConsumer = () => {

21+

ws.off?.("error", consumeAbortError);

22+

ws.off?.("close", removeAbortErrorConsumer);

23+

};

24+

try {

25+

ws.off?.("error", onError);

26+

ws.on?.("error", consumeAbortError);

27+

ws.once?.("close", removeAbortErrorConsumer);

28+

ws.terminate?.();

29+

if (typeof ws.terminate !== "function") {

30+

ws.close?.();

31+

}

32+

} finally {

33+

settle(reject, new Error(message));

34+

}

35+

}, timeoutMs);

36+
37+

timer.unref?.();

38+

ws.once("open", onOpen);

39+

ws.once("error", onError);

40+

});

41+

}

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,50 @@

1+

import { EventEmitter } from "node:events";

2+

import { describe, expect, it } from "vitest";

3+

import { waitForWebSocketOpen } from "../../scripts/e2e/lib/gateway-network/open-websocket.mjs";

4+
5+

class FakeWebSocket extends EventEmitter {

6+

terminated = false;

7+

closed = false;

8+
9+

terminate(): void {

10+

this.terminated = true;

11+

queueMicrotask(() => {

12+

this.emit("error", new Error("socket abort after terminate"));

13+

this.emit("close");

14+

});

15+

}

16+
17+

close(): void {

18+

this.closed = true;

19+

}

20+

}

21+
22+

describe("gateway network WebSocket open guard", () => {

23+

it("consumes abort errors after open timeouts", async () => {

24+

const ws = new FakeWebSocket();

25+

const keepAlive = setTimeout(() => {}, 100);

26+
27+

try {

28+

await expect(waitForWebSocketOpen(ws, 1)).rejects.toThrow("ws open timeout");

29+

} finally {

30+

clearTimeout(keepAlive);

31+

}

32+

await new Promise((resolve) => setImmediate(resolve));

33+
34+

expect(ws.terminated).toBe(true);

35+

expect(ws.listenerCount("open")).toBe(0);

36+

expect(ws.listenerCount("error")).toBe(0);

37+

});

38+
39+

it("cleans listeners after successful opens", async () => {

40+

const ws = new FakeWebSocket();

41+

const opened = waitForWebSocketOpen(ws, 100);

42+
43+

ws.emit("open");

44+
45+

await expect(opened).resolves.toBeUndefined();

46+

expect(ws.terminated).toBe(false);

47+

expect(ws.listenerCount("open")).toBe(0);

48+

expect(ws.listenerCount("error")).toBe(0);

49+

});

50+

});