Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

/live closes any text frame over 4096 bytes with 1009, counted by the relay because Bun's ws ignores maxPayload #154

Closed opened this
Closed without merging

smith/arm:smith/123-live-closes-any-text-frame-over-4096-byt → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +27 −0
Software/so101/src/lobby.test.ts +24
@@ -300,6 +300,30 @@ describe("lobby", () => {
300300 expect((await anon.next((m) => m.type === "error")).error).toContain("history");
301301 });
302302
303 test("a /live frame of 4096 bytes is handled, 4097 closes the socket with 1009; bytes, not characters", async () => {
304 const port = await start();
305 const frame = (pad: string) => JSON.stringify({ type: "history", before: "x", pad });
306 const base = Buffer.byteLength(frame(""));
307 const sized = (bytes: number, ch: string) => frame(ch.repeat(Math.ceil((bytes - base) / Buffer.byteLength(ch))));
308 const ok = await join(port);
309 const exact = sized(4096, "a");
310 expect(Buffer.byteLength(exact)).toBe(4096);
311 ok.ws.send(exact);
312 expect((await ok.next((m) => m.type === "error")).error).toContain("history");
313
314 for (const text of [sized(4097, "a"), sized(4098, "é")]) {
315 const c = await join(port);
316 expect(Buffer.byteLength(text)).toBeGreaterThan(4096);
317 const closed = new Promise<number>((r) => c.ws.once("close", (code) => r(code)));
318 c.ws.send(text);
319 expect(await closed).toBe(1009);
320 expect(c.heard.some((m) => m.type === "error")).toBe(false);
321 }
322 // characters under 4096, bytes over: still refused
323 const multi = sized(4098, "é");
324 expect(multi.length).toBeLessThan(4096);
325 });
326
303327 test("publish reaches every page on /live, signed in or not", async () => {
304328 const port = await start();
305329 const anon = await join(port);
Software/so101/src/lobby.ts +2
@@ -29,6 +29,7 @@
2929 * `publish`es to everyone: the arm's status, so a page needs this one socket for the pose, the chat and the queue.
3030 */
3131
32 import { frameBytes, TOO_BIG_CLOSE } from "./frame-limit.ts";
3233 import type { IncomingMessage } from "node:http";
3334 import type { Duplex } from "node:stream";
3435 import WebSocket, { WebSocketServer } from "ws";
@@ -261,6 +262,7 @@ export class Lobby {
261262 ws.on("message", (data, binary) => {
262263 seat.heard = Date.now();
263264 if (binary) return;
265 if (frameBytes(data) > MAX_FRAME) return ws.close(TOO_BIG_CLOSE, "frame too big");
264266 let message: unknown;
265267 try {
266268 message = JSON.parse(String(data));
forge.json +1
@@ -16,6 +16,7 @@
1616 "100.89.95.68:8101"
1717 ],
1818 "check": {
19 "run": "bun install --cwd Software/so101 --frozen-lockfile && cd Software/so101 && bun x tsc --noEmit && bun test",
1920 "limits": {
2021 "cpus": 6,
2122 "memory": 6144

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs