mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 12:56:01 -06:00
fix(clickclack): bound websocket handshake waits at 30s (#106485)
* fix(clickclack): bound websocket handshake waits at 30s
* test(clickclack): prove WebSocket handshake deadline
---------
Co-authored-by: Peter Steinberger <steipete@gmail.com>
(cherry picked from commit 3eec404aab)
This commit is contained in:
@@ -22,6 +22,10 @@ type ClientOptions = {
|
||||
};
|
||||
|
||||
const CLICKCLACK_ERROR_BODY_LIMIT_BYTES = 8 * 1024;
|
||||
// Match Slack relay / Mattermost / Signal channel gateway handshake floors.
|
||||
// Without this, gateway.ts waits forever for close/error when TCP accepts but
|
||||
// never upgrades, pinning the monitor reconnect loop.
|
||||
const CLICKCLACK_WEBSOCKET_HANDSHAKE_TIMEOUT_MS = 30_000;
|
||||
|
||||
/**
|
||||
* Creates a typed client for the ClickClack API using bearer-token auth.
|
||||
@@ -146,6 +150,7 @@ export function createClickClackClient(options: ClientOptions) {
|
||||
headers: {
|
||||
Authorization: `Bearer ${options.token}`,
|
||||
},
|
||||
handshakeTimeout: CLICKCLACK_WEBSOCKET_HANDSHAKE_TIMEOUT_MS,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// ClickClack tests cover websocket constructor options.
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { webSocketCtorCalls } = vi.hoisted(() => ({
|
||||
webSocketCtorCalls: [] as Array<{ url: string; options: unknown }>,
|
||||
}));
|
||||
|
||||
vi.mock("ws", () => ({
|
||||
WebSocket: function MockWebSocket(url: string | URL, options?: unknown) {
|
||||
webSocketCtorCalls.push({ url: String(url), options });
|
||||
},
|
||||
}));
|
||||
|
||||
import { createClickClackClient } from "./http-client.js";
|
||||
|
||||
describe("createClickClackClient websocket options", () => {
|
||||
beforeEach(() => {
|
||||
webSocketCtorCalls.length = 0;
|
||||
});
|
||||
|
||||
it("passes a 30-second opening handshake deadline to ws", () => {
|
||||
const client = createClickClackClient({
|
||||
baseUrl: "https://clickclack.example",
|
||||
token: "fake",
|
||||
});
|
||||
|
||||
client.websocket("workspace-1", "cursor-1");
|
||||
|
||||
expect(webSocketCtorCalls).toEqual([
|
||||
{
|
||||
url: "wss://clickclack.example/api/realtime/ws?workspace_id=workspace-1&after_cursor=cursor-1",
|
||||
options: {
|
||||
headers: { Authorization: "Bearer fake" },
|
||||
handshakeTimeout: 30_000,
|
||||
maxPayload: 16 * 1024 * 1024,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user