feat(transport): keep large messages intact across relay connections (#8302)

Negotiate shared binary chunk framing below application messages and routing, with bounded logical assembly and paced writes that respect encrypted relay limits. Preserve legacy admission, reconnect state, sibling route isolation, and native single-frame upload behavior.
This commit is contained in:
Mohamed Boudra
2026-10-31 09:26:24 +07:00
committed by GitHub
parent 186c132151
commit 0be49c0620
30 changed files with 1843 additions and 253 deletions
+12 -4
View File
@@ -44,12 +44,14 @@ test("a slow consumer cannot exceed the shared byte budget and close releases re
socket.pause();
await ready;
const frame = new Uint8Array(1024 * 1024);
for (let index = 0; index < 4; index++) transport.send(frame);
const writes = Array.from({ length: 4 }, () => transport.send(frame));
const drained = Promise.allSettled(writes);
expect(budget.bufferedBytes).toBe(4 * 1024 * 1024);
expect(() => transport.send(frame)).toThrow("Connected host buffer limit reached");
expect(budget.bufferedBytes).toBeLessThanOrEqual(budget.limit);
transport.close();
await expect.poll(() => budget.bufferedBytes).toBe(0);
await drained;
});
test("direct connector preserves 25 MiB binary frames in both directions", async () => {
const server = await endpoint();
@@ -65,12 +67,13 @@ test("direct connector preserves 25 MiB binary frames in both directions", async
await ready;
const bytes = new Uint8Array(25 * 1024 * 1024).fill(173);
const echoed = once(socket, "message");
transport.send(bytes);
const sending = transport.send(bytes);
const [sent, binary] = await echoed;
expect(binary).toBe(true);
expect(Buffer.from(sent as Uint8Array).equals(bytes)).toBe(true);
socket.send(bytes);
expect(Buffer.from(await received).equals(bytes)).toBe(true);
await sending;
});
import {
@@ -124,24 +127,29 @@ test("encrypted connector rejects overload synchronously and preserves the physi
});
await new Promise<void>((resolve) => transport.onOpen(resolve));
await ready;
expect(transport.maxFrameBytes).toBeLessThan(32 * 1024 * 1024);
peer.pause();
const frame = new Uint8Array(1024 * 1024).fill(173);
let rejected: unknown;
const writes: (void | Promise<void>)[] = [];
for (let index = 0; index < 8; index++) {
try {
transport.send(frame);
writes.push(transport.send(frame));
} catch (error) {
rejected = error;
break;
}
}
const drained = Promise.allSettled(writes);
expect(rejected).toMatchObject({ code: "resource_limit" });
expect(budget.bufferedBytes).toBeLessThanOrEqual(budget.limit);
await new Promise<void>((resolve) => setImmediate(resolve));
expect(errors).toEqual([]);
expect(closed).toBe(false);
transport.send("sibling control");
const sibling = transport.send("sibling control");
peer.resume();
await drained;
await sibling;
await expect.poll(() => received.includes("sibling control")).toBe(true);
expect(received.filter((data) => data instanceof ArrayBuffer).length).toBeGreaterThan(0);
expect(
+7 -1
View File
@@ -172,9 +172,15 @@ export function createHostTransportFactory(
close();
});
return {
get supportsDrain() {
return transport?.supportsDrain;
},
get maxFrameBytes() {
return transport?.maxFrameBytes;
},
send(data) {
if (closed || !transport) throw new Error("Host transport is unavailable");
transport.send(data);
return transport.send(data);
},
close,
onOpen(handler) {