Handle oversized websocket payload errors safely

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 00:59:45 +00:00
1 parent 9a5a8c7e5d
commit d013808e3f
2 files changed
+37

No files matched your search

+33
View File
@@ -434,6 +434,39 @@ describe("runtimeApiServer", () => {
client.socket.close();
});
it("closes oversized websocket payloads and remains available", async () => {
const server = await startRuntimeApiServer({
port: 0,
launchCwd: process.cwd(),
});
servers.push(server);
const firstClient = await connectClient(server.wsUrl);
await firstClient.nextMessage();
const firstClose = withTimeout(
new Promise<number>((resolve) => {
firstClient.socket.once("close", (code) => resolve(code));
}),
10_000,
);
firstClient.socket.send("x".repeat(6 * 1024 * 1024));
const closeCode = await firstClose;
expect([1006, 1009]).toContain(closeCode);
const secondClient = await connectClient(server.wsUrl);
await secondClient.nextMessage();
const response = await sendRequest(
secondClient.socket,
secondClient.nextMessage,
"todos-after-large-payload",
"todos.list",
);
expect(response.ok).toBe(true);
secondClient.socket.close();
});
it("accepts buffer-encoded websocket request payloads", async () => {
const server = await startRuntimeApiServer({
port: 0,
+4
View File
@@ -646,6 +646,10 @@ export async function startRuntimeApiServer(
activeClient = null;
}
});
socket.on("error", () => {
// Connection-level protocol/socket errors are expected occasionally
// (for example oversized client payloads). Keep server process alive.
});
});
try {