Both were synchronous and left the boot to the first request, with the fix documented as something the caller should remember: `await app.boot()` before `Deno.serve` / `Bun.serve`. That made the correct use of a core helper depend on reading a README, in a framework whose whole argument is that order should not be something you have to get right. The failure it leaves is the bad kind. `app.fetch` boots lazily and the boot memo keeps the *rejection*, so a missing signing key does not fail the deploy: the port binds, every request is answered 500 by the runtime, and none of them reach `onError`. Anything that health-checks by asking whether the process is listening sees a healthy server. `listen()` has always awaited `bootApp()` before binding its socket, with a comment saying it exists so Node and Deno/Bun serve an identical graph. They did not. Now the three helpers agree, and the two adapters return promises. `edgeHandler` is deliberately unchanged: on workerd there is no startup outside a request, so there is no earlier moment to move the failure to. Both new tests were confirmed to fail with the gate commented out — without it `serveBun` resolves instead of rejecting, and serveDeno binds a port that 500s. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
54 lines
2.0 KiB
TypeScript
54 lines
2.0 KiB
TypeScript
// The teapot's frame loop under Deno, driven by a raw client rather than by another green-tea.
|
|
//
|
|
// The two guards here are close-code behaviour, and close codes are exactly where the runtimes
|
|
// have already differed once — a client may only send 1000 or 3000-4999, which is why the mesh
|
|
// heartbeat uses 4011 instead of 1011. Server-side closes deserve the same suspicion.
|
|
//
|
|
// Run with: npm run test:deno
|
|
import 'npm:reflect-metadata';
|
|
import { assertEquals } from 'jsr:@std/assert';
|
|
import { createApp, Step, Module } from '../../src/index.ts';
|
|
import { serveDeno } from '../../src/deno.ts';
|
|
|
|
@Step({ provides: 'auth', needs: [], export: true })
|
|
class Auth {
|
|
run() {
|
|
return { auth: { ok: true } };
|
|
}
|
|
}
|
|
@Module({ mountpoint: '/api', steps: [Auth] })
|
|
class TeapotModule {}
|
|
|
|
async function startTeapot() {
|
|
const app = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: 'good' } });
|
|
let port = 0;
|
|
const server = await serveDeno(app, { port: 0, onListen: (addr) => (port = addr.port) });
|
|
await new Promise((r) => setTimeout(r, 50));
|
|
|
|
return { port: () => port, stop: async () => { await server.shutdown(); await app.close(); } };
|
|
}
|
|
|
|
/** Opens a raw control-channel socket and resolves with how it ended. */
|
|
function rawClient(port: number, send: string): Promise<{ code: number }> {
|
|
return new Promise((resolve, reject) => {
|
|
const ws = new WebSocket(`ws://127.0.0.1:${port}/__mesh__/control`);
|
|
ws.onopen = () => ws.send(send);
|
|
ws.onclose = (event) => resolve({ code: event.code });
|
|
ws.onerror = () => reject(new Error('socket errored'));
|
|
});
|
|
}
|
|
|
|
Deno.test('mesh on Deno: the teapot hangs up on an oversized control frame', async () => {
|
|
const teapot = await startTeapot();
|
|
|
|
try {
|
|
// over the 4,000,000-character cap, and sent by a peer that has not authenticated
|
|
const oversized = `{"type":"hello","v":1,"secret":"${'a'.repeat(4_000_001)}"}`;
|
|
const { code } = await rawClient(teapot.port(), oversized);
|
|
|
|
assertEquals(code, 1009);
|
|
} finally {
|
|
await teapot.stop();
|
|
}
|
|
});
|