From d013808e3fc3ff7979ffaf6ce678bcbeb3e59230 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 00:59:45 +0000 Subject: [PATCH] Handle oversized websocket payload errors safely Co-authored-by: Theo Browne --- apps/t3/src/runtimeApiServer.test.ts | 33 ++++++++++++++++++++++++++++ apps/t3/src/runtimeApiServer.ts | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 58865ae902..65072d5d10 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -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((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, diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index 621f7911b1..1931cd94f9 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -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 {