test(bun): expect 1009 for oversized WebSocket frames on Bun 1.4+
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / runtimes (deno) (pull_request) Successful in 20s
CI / runtimes (edge) (pull_request) Successful in 14s
CI / build (pull_request) Successful in 27s

CI picked up Bun 1.4.4 (`oven-sh/setup-bun@v2`, latest), which now sends a
real `1009` close frame when `maxPayloadLength` refuses a frame. Bun 1.3
dropped the connection instead, so the peer saw `1006` — the difference D1
documented and these two assertions pinned on purpose so a Bun upgrade would
be noticed. It was: `runtimes (bun)` fails on develop.

The assertion now follows `Bun.version` (1006 before 1.4, 1009 from 1.4), so a
further change in either direction still fails. JSDoc, README and the #107
CHANGELOG entry say which Bun versions do what.

Verified with Bun 1.3.14 and 1.4.4 (26/26 each); lint, format, typecheck,
npm test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnxandClaude Opus 5.5 committed 2026-10-22 23:50:30 -05:00
1 parent 169ffe6b88
commit 69bdc8adec
5 files changed
+15 -13

No files matched your search

+8 -6
View File
@@ -101,10 +101,12 @@ function exchange(port: number, path: string, frames: string[], until = 2000) {
});
}
// #107: Bun refuses an oversized frame natively (`maxPayloadLength`), before buffering it. Its
// uWebSockets core drops the TCP connection without a close frame, so the peer sees `1006`, not
// the `1009` Node, Deno and the edge send. Asserted rather than papered over: it is the documented
// Bun difference, and a Bun upgrade that starts sending 1009 should fail here and be noticed.
// #107: Bun refuses an oversized frame natively (`maxPayloadLength`), before buffering it. Up to
// Bun 1.3 its uWebSockets core dropped the TCP connection without a close frame, so the peer saw
// `1006`; from Bun 1.4 it sends a real `1009`, like Node, Deno and the edge. Asserted per version
// rather than papered over, so a further change in either direction fails here and is noticed.
const [bunMajor, bunMinor] = Bun.version.split('.').map(Number);
const OVERSIZE_CLOSE = bunMajor > 1 || (bunMajor === 1 && bunMinor >= 4) ? 1009 : 1006;
test('serveBun: ws message size and inbound queue limits', async () => {
const app = createApp({ modules: [M], limits: { maxWsMessageBytes: 1024, maxWsQueue: 4 } });
const server = await serveBun(app, { port: 0 });
@@ -114,7 +116,7 @@ test('serveBun: ws message size and inbound queue limits', async () => {
expect(atLimit.replies).toEqual([`echo:${'a'.repeat(1024)}`]);
const over = await exchange(port, '/rt/echo', ['a'.repeat(1025)]);
expect(over.close?.code).toBe(1006);
expect(over.close?.code).toBe(OVERSIZE_CLOSE);
const full = await exchange(port, '/rt/stall', ['1', '2', '3', '4', '5']);
expect(full.close).toEqual({ code: 1013, reason: 'inbound queue full' });
@@ -132,7 +134,7 @@ test('serveBun: ws message size default is 1 MiB', async () => {
expect(atLimit.replies.length).toBe(1);
const over = await exchange(port, '/rt/echo', ['a'.repeat(1_048_577)]);
expect(over.close?.code).toBe(1006);
expect(over.close?.code).toBe(OVERSIZE_CLOSE);
} finally {
server.stop(true);
}