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
smith/arm:smith/123-live-closes-any-text-frame-over-4096-byt → main 2 commits fork
3 files
changed +27
−0
Software/so101/src/lobby.test.ts +24
| @@ -300,6 +300,30 @@ describe("lobby", () => { | ||
| 300 | 300 | expect((await anon.next((m) => m.type === "error")).error).toContain("history"); |
| 301 | 301 | }); |
| 302 | 302 | |
| 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 | ||
| 303 | 327 | test("publish reaches every page on /live, signed in or not", async () => { |
| 304 | 328 | const port = await start(); |
| 305 | 329 | const anon = await join(port); |
Software/so101/src/lobby.ts +2
| @@ -29,6 +29,7 @@ | ||
| 29 | 29 | * `publish`es to everyone: the arm's status, so a page needs this one socket for the pose, the chat and the queue. |
| 30 | 30 | */ |
| 31 | 31 | |
| 32 | import { frameBytes, TOO_BIG_CLOSE } from "./frame-limit.ts"; | |
| 32 | 33 | import type { IncomingMessage } from "node:http"; |
| 33 | 34 | import type { Duplex } from "node:stream"; |
| 34 | 35 | import WebSocket, { WebSocketServer } from "ws"; |
| @@ -261,6 +262,7 @@ export class Lobby { | ||
| 261 | 262 | ws.on("message", (data, binary) => { |
| 262 | 263 | seat.heard = Date.now(); |
| 263 | 264 | if (binary) return; |
| 265 | if (frameBytes(data) > MAX_FRAME) return ws.close(TOO_BIG_CLOSE, "frame too big"); | |
| 264 | 266 | let message: unknown; |
| 265 | 267 | try { |
| 266 | 268 | message = JSON.parse(String(data)); |
forge.json +1
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | "100.89.95.68:8101" |
| 17 | 17 | ], |
| 18 | 18 | "check": { |
| 19 | "run": "bun install --cwd Software/so101 --frozen-lockfile && cd Software/so101 && bun x tsc --noEmit && bun test", | |
| 19 | 20 | "limits": { |
| 20 | 21 | "cpus": 6, |
| 21 | 22 | "memory": 6144 |
new above
offline