Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1145eab371 |
No files matched your search
@@ -119,14 +119,6 @@ npm treats versions as semver and semver forbids leading zeros.
|
|||||||
`1009`, on every Bun version, where Bun before 1.4 refused natively by dropping the connection
|
`1009`, on every Bun version, where Bun before 1.4 refused natively by dropping the connection
|
||||||
(`1006`).
|
(`1006`).
|
||||||
|
|
||||||
- **More than 16 mesh RPCs in flight on one link no longer drop the control channel** (#148). The
|
|
||||||
16-frame inbound queue from #107 (`limits.maxWsQueue`) also applied to the control channel. On
|
|
||||||
Node, `ws` delivers every frame of one socket read at once, so a teacup sending a burst of RPCs
|
|
||||||
got the channel closed with `1013`, and every pending request failed with `503`. The control
|
|
||||||
channel now has its own queue bound of 4,096 frames, or `maxWsQueue` if that is larger, which is
|
|
||||||
more than one socket read can carry. User `@Ws` routes keep closing `1013` at `maxWsQueue`. Deno
|
|
||||||
and Bun deliver frames one at a time and did not hit this, but they now share the same bound.
|
|
||||||
|
|
||||||
- **`static` no longer serves files outside its root through a symlink** (#106). The traversal guard
|
- **`static` no longer serves files outside its root through a symlink** (#106). The traversal guard
|
||||||
compared paths lexically, and the file read then followed symlinks, so `public/leak -> /etc/hosts`
|
compared paths lexically, and the file read then followed symlinks, so `public/leak -> /etc/hosts`
|
||||||
was served. Containment now compares real paths: the requested file, and a directory's
|
was served. Containment now compares real paths: the requested file, and a directory's
|
||||||
|
|||||||
+5
-19
@@ -58,29 +58,15 @@ export function wsMessageBytes(limits: Pick<RequestLimits, 'maxWsMessageBytes'>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undelivered inbound frames the mesh control channel may hold (#148), in place of
|
* The limits the mesh control channel's socket is bounded by (#120): `limits` with
|
||||||
* `limits.maxWsQueue` when larger. Its consumer, the teapot's frame loop, never awaits between
|
* `maxWsMessageBytes` raised to the channel's own frame bound when that is larger. A user route
|
||||||
* frames, so its queue only ever holds one delivery burst: `ws` emits every frame of one socket
|
* never goes through this, so it keeps `maxWsMessageBytes` as configured.
|
||||||
* read synchronously, and a read is at most 64 KiB, under 4,096 of the smallest control frame
|
|
||||||
* (`{"type":"ping"}`). A teacup with many RPCs in flight sends exactly such bursts, which the
|
|
||||||
* 16-frame user default closed with 1013. Still finite, so a peer flooding the channel while
|
|
||||||
* nothing reads it — before the boot finishes, say — is still cut off.
|
|
||||||
*/
|
|
||||||
const CONTROL_QUEUE = 4096;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The limits the mesh control channel's socket is bounded by: `limits` with `maxWsMessageBytes`
|
|
||||||
* raised to the channel's own frame bound (#120) and `maxWsQueue` to {@link CONTROL_QUEUE} (#148),
|
|
||||||
* each only when larger. A user route never goes through this, so it keeps both as configured.
|
|
||||||
*/
|
*/
|
||||||
export function controlLimits(
|
export function controlLimits(
|
||||||
limits: Pick<RequestLimits, 'maxWsMessageBytes' | 'maxWsQueue'> | undefined,
|
limits: Pick<RequestLimits, 'maxWsMessageBytes' | 'maxWsQueue'> | undefined,
|
||||||
maxFrameBytes: number | undefined,
|
maxFrameBytes: number | undefined,
|
||||||
): { maxWsMessageBytes: number; maxWsQueue: number } {
|
): Pick<RequestLimits, 'maxWsQueue'> & { maxWsMessageBytes: number } {
|
||||||
return {
|
return { ...limits, maxWsMessageBytes: Math.max(wsMessageBytes(limits), maxFrameBytes ?? 0) };
|
||||||
maxWsMessageBytes: Math.max(wsMessageBytes(limits), maxFrameBytes ?? 0),
|
|
||||||
maxWsQueue: Math.max(limits?.maxWsQueue ?? DEFAULT_MAX_WS_QUEUE, CONTROL_QUEUE),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Throws when a WebSocket limit is present but not a positive safe integer (#107). */
|
/** Throws when a WebSocket limit is present but not a positive safe integer (#107). */
|
||||||
|
|||||||
@@ -24,15 +24,6 @@ class BigCtl {
|
|||||||
for await (const msg of inbound) yield `echo:${String(msg).length}`;
|
for await (const msg of inbound) yield `echo:${String(msg).length}`;
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never reads `inbound`: every frame stays queued, so the 17th closes 1013 (#107).
|
|
||||||
@Ws('/stall')
|
|
||||||
stall() {
|
|
||||||
return (async function* () {
|
|
||||||
await new Promise<never>(() => {});
|
|
||||||
yield '';
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@Module({ mountpoint: '/api', controllers: [BigCtl] })
|
@Module({ mountpoint: '/api', controllers: [BigCtl] })
|
||||||
class TeapotModule {}
|
class TeapotModule {}
|
||||||
@@ -143,40 +134,3 @@ test('mesh on Bun: the control-channel cap follows a raised maxBodyBytes (T4)',
|
|||||||
await close();
|
await close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('mesh on Bun: 64 concurrent RPCs on one link all succeed (#148)', async () => {
|
|
||||||
const { post, close, teacup } = await pair();
|
|
||||||
try {
|
|
||||||
// In one tick, through `app.fetch`: all 64 rpc-req frames leave together and land in one read,
|
|
||||||
// which is the burst that tripped the 16-frame queue. Over HTTP sockets they trickle in.
|
|
||||||
const rpc = () =>
|
|
||||||
teacup.fetch(
|
|
||||||
new Request('http://x/api/big/echo', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'content-type': 'application/json' },
|
|
||||||
body: json(100),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const res = await Promise.all(Array.from({ length: 64 }, rpc));
|
|
||||||
expect(res.map((r) => r.status)).toEqual(Array(64).fill(200));
|
|
||||||
expect((await post(json(1_000))).status).toEqual(200);
|
|
||||||
} finally {
|
|
||||||
await close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('mesh on Bun: a user ws route on the same teapot still closes 1013 at maxWsQueue (#148)', async () => {
|
|
||||||
const { close, tPort } = await pair();
|
|
||||||
try {
|
|
||||||
const code = await new Promise<number>((resolve) => {
|
|
||||||
const ws = new WebSocket(`ws://127.0.0.1:${tPort}/api/big/stall`);
|
|
||||||
ws.onopen = () => {
|
|
||||||
for (let i = 0; i < 17; i++) ws.send(String(i));
|
|
||||||
};
|
|
||||||
ws.onclose = (e) => resolve(e.code);
|
|
||||||
});
|
|
||||||
expect(code).toEqual(1013);
|
|
||||||
} finally {
|
|
||||||
await close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -24,15 +24,6 @@ class BigCtl {
|
|||||||
for await (const msg of inbound) yield `echo:${String(msg).length}`;
|
for await (const msg of inbound) yield `echo:${String(msg).length}`;
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never reads `inbound`: every frame stays queued, so the 17th closes 1013 (#107).
|
|
||||||
@Ws('/stall')
|
|
||||||
stall() {
|
|
||||||
return (async function* () {
|
|
||||||
await new Promise<never>(() => {});
|
|
||||||
yield '';
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@Module({ mountpoint: '/api', controllers: [BigCtl] })
|
@Module({ mountpoint: '/api', controllers: [BigCtl] })
|
||||||
class TeapotModule {}
|
class TeapotModule {}
|
||||||
@@ -76,7 +67,7 @@ async function pair(maxBodyBytes?: number) {
|
|||||||
await c.server.shutdown();
|
await c.server.shutdown();
|
||||||
await t.server.shutdown();
|
await t.server.shutdown();
|
||||||
};
|
};
|
||||||
return { post, close, tPort: t.port, teacup };
|
return { post, close, tPort: t.port };
|
||||||
}
|
}
|
||||||
|
|
||||||
const json = (bytes: number) => JSON.stringify({ data: 'x'.repeat(bytes - WRAP) });
|
const json = (bytes: number) => JSON.stringify({ data: 'x'.repeat(bytes - WRAP) });
|
||||||
@@ -139,40 +130,3 @@ Deno.test('mesh on Deno: the control-channel cap follows a raised maxBodyBytes (
|
|||||||
await close();
|
await close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test('mesh on Deno: 64 concurrent RPCs on one link all succeed (#148)', async () => {
|
|
||||||
const { post, close, teacup } = await pair();
|
|
||||||
try {
|
|
||||||
// In one tick, through `app.fetch`: all 64 rpc-req frames leave together and land in one read,
|
|
||||||
// which is the burst that tripped the 16-frame queue. Over HTTP sockets they trickle in.
|
|
||||||
const rpc = () =>
|
|
||||||
teacup.fetch(
|
|
||||||
new Request('http://x/api/big/echo', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'content-type': 'application/json' },
|
|
||||||
body: json(100),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const res = await Promise.all(Array.from({ length: 64 }, rpc));
|
|
||||||
assertEquals(res.map((r) => r.status), Array(64).fill(200));
|
|
||||||
assertEquals((await post(json(1_000))).status, 200);
|
|
||||||
} finally {
|
|
||||||
await close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test('mesh on Deno: a user ws route on the same teapot still closes 1013 at maxWsQueue (#148)', async () => {
|
|
||||||
const { close, tPort } = await pair();
|
|
||||||
try {
|
|
||||||
const code = await new Promise<number>((resolve) => {
|
|
||||||
const ws = new WebSocket(`ws://127.0.0.1:${tPort}/api/big/stall`);
|
|
||||||
ws.onopen = () => {
|
|
||||||
for (let i = 0; i < 17; i++) ws.send(String(i));
|
|
||||||
};
|
|
||||||
ws.onclose = (e) => resolve(e.code);
|
|
||||||
});
|
|
||||||
assertEquals(code, 1013);
|
|
||||||
} finally {
|
|
||||||
await close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
@@ -7,8 +7,7 @@
|
|||||||
// - a text body does not: every `"` or `\` doubles under JSON escaping, so a 999 KB text body
|
// - a text body does not: every `"` or `\` doubles under JSON escaping, so a 999 KB text body
|
||||||
// became a ~2 MB frame and the teapot hung up the whole channel with 1009 (T1b);
|
// became a ~2 MB frame and the teapot hung up the whole channel with 1009 (T1b);
|
||||||
// - a raised `maxBodyBytes` was capped at 1 MiB on the channel regardless (T4).
|
// - a raised `maxBodyBytes` was capped at 1 MiB on the channel regardless (T4).
|
||||||
// Its queue bound had the same problem (#148): `maxWsQueue` (16) closed it 1013 under a burst of
|
// The Deno and Bun twins live in test/deno and test/bun.
|
||||||
// RPCs, which Node's `ws` delivers in one go. The Deno and Bun twins live in test/deno and test/bun.
|
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import WebSocket from 'ws';
|
import WebSocket from 'ws';
|
||||||
import { createApp, Route, Post, Module, Ws, body, ctx } from '../../src/index';
|
import { createApp, Route, Post, Module, Ws, body, ctx } from '../../src/index';
|
||||||
@@ -29,15 +28,6 @@ class BigCtl {
|
|||||||
for await (const msg of inbound) yield `echo:${String(msg).length}`;
|
for await (const msg of inbound) yield `echo:${String(msg).length}`;
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Never reads `inbound`: every frame stays queued, so the 17th closes 1013 (#107).
|
|
||||||
@Ws('/stall')
|
|
||||||
stall() {
|
|
||||||
return (async function* () {
|
|
||||||
await new Promise<never>(() => {});
|
|
||||||
yield '';
|
|
||||||
})();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@Module({ mountpoint: '/api', controllers: [BigCtl] })
|
@Module({ mountpoint: '/api', controllers: [BigCtl] })
|
||||||
class TeapotModule {}
|
class TeapotModule {}
|
||||||
@@ -63,7 +53,7 @@ async function pair(maxBodyBytes?: number) {
|
|||||||
await teacup.close();
|
await teacup.close();
|
||||||
await teapot.close();
|
await teapot.close();
|
||||||
};
|
};
|
||||||
return { post, close, tPort, teacup };
|
return { post, close, tPort };
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('mesh RPC body near maxBodyBytes (#120)', () => {
|
describe('mesh RPC body near maxBodyBytes (#120)', () => {
|
||||||
@@ -124,37 +114,4 @@ describe('mesh RPC body near maxBodyBytes (#120)', () => {
|
|||||||
await close();
|
await close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
it('64 concurrent RPCs on one link all succeed: the control channel has its own queue bound (#148)', async () => {
|
|
||||||
const { post, close, teacup } = await pair();
|
|
||||||
try {
|
|
||||||
// In one tick, through `app.fetch`: all 64 rpc-req frames leave together and land in one read,
|
|
||||||
// which is the burst that tripped the 16-frame queue. Over HTTP sockets they trickle in.
|
|
||||||
const rpc = () =>
|
|
||||||
teacup.fetch(
|
|
||||||
new Request('http://x/api/big/echo', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'content-type': 'application/json' },
|
|
||||||
body: json(100),
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
const res = await Promise.all(Array.from({ length: 64 }, rpc));
|
|
||||||
expect(res.map((r) => r.status)).toEqual(Array(64).fill(200));
|
|
||||||
expect((await post(json(1_000))).status).toBe(200);
|
|
||||||
} finally {
|
|
||||||
await close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('a user ws route on the same teapot still closes 1013 at maxWsQueue (#148)', async () => {
|
|
||||||
const { close, tPort } = await pair();
|
|
||||||
try {
|
|
||||||
const ws = new WebSocket(`ws://127.0.0.1:${tPort}/api/big/stall`);
|
|
||||||
await new Promise((resolve) => ws.once('open', resolve));
|
|
||||||
const closed = new Promise<number>((resolve) => ws.once('close', (code) => resolve(code)));
|
|
||||||
for (let i = 0; i < 17; i++) ws.send(String(i));
|
|
||||||
expect(await closed).toBe(1013);
|
|
||||||
} finally {
|
|
||||||
await close();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user