feat(runtime)!: serveDeno and serveBun boot before they bind #98

Merged
chrnx merged 1 commits from feature/serve-adapters-boot into develop 2026-09-20 16:55:49 +00:00
Owner

Closes the gap Diego spotted reading @green-tea/jwt's README, which told the reader to call app.boot() before Deno.serve / Bun.serve.

That note was accurate, and that is the problem. It documented a core helper whose correct use depended on the caller remembering something — in a framework whose argument is that order should not be a thing you have to get right.

Why the old failure was the bad kind

listen() has always done await bootApp() before binding its socket (src/app/index.ts:328), with a comment saying it exists "so Node and Deno/Bun serve an identical graph". They did not: serveDeno and serveBun were synchronous and left boot to app.fetch.

app.fetch boots lazily and the boot memo keeps the rejection. So a missing signing key was not a failed deploy:

  • the port binds
  • every request is answered 500 by the runtime
  • none of them reach onError
  • anything health-checking by "is it listening?" sees a healthy server

The change

serveDeno and serveBun are async, returning Promise<DenoServer> and Promise<BunServeResult>. The returned value is unchanged, so migration is one keyword:

- const server = serveDeno(app, { port });
+ const server = await serveDeno(app, { port });

Both runtimes support top-level await, so a module that serves at import time needs nothing else. This is what the shutdown examples already do with the result, and the app still owns its own close.

edgeHandler is deliberately untouched: on workerd there is no startup outside a request, so there is no earlier moment to move the failure to. That is now the only place the lazy path is documented, and there it is true.

Verification

Two new integration tests, one per runtime, asserting a failing provider rejects the serve call instead of binding a port that 500s. Both confirmed to bite — with await app.boot() commented out, serveBun resolves instead of rejecting and the Deno test reports <resolved>.

Gate Result
lint / format / complexity / typecheck pass
vitest 567 passed
Deno 18 passed
Bun 8 passed
workerd (miniflare) PASS
deno publish --dry-run Success

Every call site updated: 12 test files, 2 bench servers. One Bun helper (startTeapot) had to become async, which is the only non-mechanical edit.

Docs: a ### Breaking entry with the diff, and the [Unreleased] app.boot() entry rewritten — it described the old behaviour and had not shipped yet. App.boot's JSDoc now says the helpers call it and hand-calling is for app.fetch / app.upgrade driven by your own server. The README needed nothing: it has no code example using either adapter.

Closes the gap Diego spotted reading `@green-tea/jwt`'s README, which told the reader to call `app.boot()` before `Deno.serve` / `Bun.serve`. That note was accurate, and that is the problem. It documented a core helper whose correct use depended on the caller remembering something — in a framework whose argument is that order should not be a thing you have to get right. ## Why the old failure was the bad kind `listen()` has always done `await bootApp()` before binding its socket (`src/app/index.ts:328`), with a comment saying it exists *"so Node and Deno/Bun serve an identical graph"*. They did not: `serveDeno` and `serveBun` were synchronous and left boot to `app.fetch`. `app.fetch` boots lazily and the boot memo keeps the **rejection**. So a missing signing key was not a failed deploy: - the port binds - every request is answered `500` by the runtime - none of them reach `onError` - anything health-checking by "is it listening?" sees a healthy server ## The change `serveDeno` and `serveBun` are `async`, returning `Promise<DenoServer>` and `Promise<BunServeResult>`. The returned value is unchanged, so migration is one keyword: ```diff - const server = serveDeno(app, { port }); + const server = await serveDeno(app, { port }); ``` Both runtimes support top-level `await`, so a module that serves at import time needs nothing else. This is what the shutdown examples already do with the result, and the app still owns its own close. `edgeHandler` is deliberately untouched: on workerd there is no startup outside a request, so there is no earlier moment to move the failure to. That is now the only place the lazy path is documented, and there it is true. ## Verification Two new integration tests, one per runtime, asserting a failing provider rejects the serve call instead of binding a port that 500s. **Both confirmed to bite** — with `await app.boot()` commented out, `serveBun` resolves instead of rejecting and the Deno test reports `<resolved>`. | Gate | Result | | --- | --- | | lint / format / complexity / typecheck | pass | | vitest | 567 passed | | Deno | 18 passed | | Bun | 8 passed | | workerd (miniflare) | PASS | | `deno publish --dry-run` | Success | Every call site updated: 12 test files, 2 bench servers. One Bun helper (`startTeapot`) had to become `async`, which is the only non-mechanical edit. Docs: a `### Breaking` entry with the diff, and the `[Unreleased]` `app.boot()` entry rewritten — it described the old behaviour and had not shipped yet. `App.boot`'s JSDoc now says the helpers call it and hand-calling is for `app.fetch` / `app.upgrade` driven by your own server. The README needed nothing: it has no code example using either adapter.
chrnx added 1 commit 2026-09-19 17:39:15 +00:00
feat(runtime)!: serveDeno and serveBun boot before they bind
CI / dco (pull_request) Successful in 6s
CI / build (pull_request) Successful in 30s
CI / runtimes (bun) (pull_request) Successful in 16s
CI / runtimes (deno) (pull_request) Successful in 20s
CI / runtimes (edge) (pull_request) Successful in 13s
9634ec73e8
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>
chrnx merged commit a57223cef9 into develop 2026-09-20 16:55:49 +00:00
Sign in to join this conversation.