Container.resolve marked an app-scoped binding resolved only after its
factory settled. Two resolutions that started before then both found
nothing cached and both ran the factory, so one token could open two
pools.
The binding now caches the promise as soon as the factory starts, and
every resolution returns that promise. Retry semantics are unchanged:
before, a rejected factory set nothing and the next resolution ran it
again. Now a rejection clears the cached promise, so the next
resolution still retries, and only the callers already waiting on the
failed attempt share its rejection. The factory runs inside an async
wrapper so a synchronous throw takes the same path.
createApp was not exposed to this in practice. bootProvider runs each
provider's runner once, inside the memoized boot, and registers the
finished value as a constant factory, and Container is not exported.
The fix makes the container's own guarantee hold instead of relying on
that.
Refs: GitHub #46
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
record in params.ts read the argument map with Reflect.getMetadata,
which walks the prototype chain, then pushed into the list it got back
and defined that same object on the subclass. On a subclass with no
metadata of its own, that object was the base class's, so a @query on
Child.list also showed up in getArgs(Base, 'list').
routeDecorator in metadata.ts had the same pattern with the routes
array, so a @Get on a subclass was also served by the base controller.
It is the same bug in the same shape, so it is fixed here too.
Both now write a copy onto the decorated class: a shallow copy of the
map and a new list for the method in params.ts, a new array in
metadata.ts. getMetadata returns the class's own metadata once it has
some, so later decorators on that class copy its own data, not the
base's. A subclass still starts from what it inherits, as before.
The other decorators in metadata.ts (@Provider, @Step, @Route,
@Module, @Transformer, @Html) define a fresh value per class or per
method and never mutate what they read, so they are unaffected.
Refs: GitHub #44
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Both stream adapters waited for the source's pending next() after the
client had disconnected. A source idle between events, such as an SSE
feed with nothing to send, may never settle that next(), so on Node
pipeStream never reached its finally: stream:close did not fire and the
closer stayed registered, which graceful shutdown then still treated as
a live stream. Through app.fetch, the ReadableStream's cancel awaited
return(), which an async generator only runs once its pending next()
settles, so cancelling the body did not settle either, with or without
compression wrapping it.
Each pull is now raced against the disconnect: the response's close
event on Node, and the stream's cancel on the fetch path. The source's
return() is called without being waited on, through a small
releaseIterator helper that also guards a return() that throws
synchronously, which on Node escaped from the close listener as an
uncaught exception. The WebSocket abort listener already released its
iterator this way and now uses the same helper.
The new cases in stream-lifecycle-parity drive both adapters, with and
without compression, against an async generator, a return() that never
settles and a return() that throws. All twelve need the fix except the
uncompressed fetch case with a generator, which already passed.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
closeWithDeadline called graceful() directly inside the Promise
executor. A graceful path that threw before returning its promise
escaped the executor, so the close() that serveDeno and serveBun
return rejected on the spot. The deadline timer had already been armed
and nothing cleared it, so it later fired anyway: it logged a timeout
and forced a server whose close() had already given up.
graceful() now runs inside Promise.resolve().then(), so a synchronous
throw becomes a rejection and takes the same path one already took: the
shutdown ends, close() resolves, and the timer is cleared.
GitHub #47.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
TeardownRegistry.run set a `drained` flag and returned at once to any
later caller. That kept teardown from running twice, but a second
close() made while the first was still awaiting its callbacks resolved
straight away. A signal handler and a test hook closing together could
then move on with a database the first call had not closed yet. This
reached every close path: app.close() with or without a listen()ed
server, and serveDeno/serveBun, which hand over to app.close().
The registry now keeps the promise of the teardown it started and
returns it to every caller, so the callbacks still run once and each
caller resolves only after they finish, within its own runTeardown
budget. The drain window and closeApp needed no change: the health
drain already shares one window, and a second server.close() waits for
the same 'close' event. close() after a failed listen() still has no
server and only runs teardown.
GitHub #45.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Exact matching left `application/json-patch+json` arriving as text,
where the old substring check had parsed it, and still left the other
`+json` types (`application/problem+json`, `application/vnd.api+json`)
as text, as they always were. `+json` is the structured-syntax suffix
for JSON (RFC 6839), so any media type ending in it is parsed as JSON.
`application/jsonx` and parameters that only mention JSON still are not.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
parseRequestBody picked JSON, urlencoded or multipart with
contentType.includes() on the raw header. That is case-sensitive, so a
valid `Application/JSON` reached the handler as a string, and it
matches anywhere in the header, so a parameter could choose the
parser: `text/plain; x=application/json` was parsed as JSON.
The media type is now taken from the part before any `;`, trimmed and
lowercased (RFC 9110 §8.3.1), and compared exactly. The boundary is
still read from the full header.
A type that merely contains one of the three no longer selects its
parser. `application/json-patch+json` used to be parsed as JSON and
now arrives as text, as other `+json` types always have. CHANGELOG
says so.
test/http.test.ts sends both cases from the issue, plus their
urlencoded equivalents, through the Node server.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
GitHub #32 (merged from contrib) made `createApp` fail with a message
naming the module when its `@Module` metadata has no `mountpoint`,
instead of a TypeError from `joinPath`. The check tested falsiness, so
it also refused `mountpoint: ''`, which the type allows and which has
always mounted at the root (`joinPath('', '/hi')` is `/hi`).
Test for `typeof … !== 'string'` instead: a missing or non-string
mountpoint still fails with the new message, and `''` boots as before.
The CHANGELOG entry for #31 that #32 did not add is included.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Two Breaking entries in [Unreleased] described a new boot failure
without the step that fixes it. Found in the second pre-freeze review.
- #127, constrained route params that tie: make the constraints
disjoint, keep one route and branch in the handler, or give one its
own static segment. A plain param reported unreachable never served a
request, so delete it or narrow the constraint that shadows it. For a
WebSocket pair, declare the constrained route first.
- #126, reserved `/__mesh__/control`: move the route to another path.
Nothing replaces the reserved one, which never reached a route on
Deno, Bun or the edge.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
D19 as amended 2026-10-24: nothing that shipped in 26.9.0-beta.2 is
removed. Every symbol D19 had listed for removal or review is in that
release, so this change only adds exports and marks scope.
- Export `AppOptions`, `ExplainNode`, `WsRequest` and `WsSocket`. Each
appears in a public signature (`createApp`, `Explain.chain`,
`app.upgrade`) but could not be imported. `AppOptions` is the former
inline options type of `createApp`, moved verbatim into an interface.
- Add `RequestHeaders`. `Headers` shadows the Fetch global wherever it
is imported, so it stays only as a `@deprecated` alias of the same type.
- Mark the mesh exports and `MeshConfig` `@experimental`. They stay
exported and unchanged, but sit outside the freeze, like the
`experimental: true` flag the mesh already needs.
- The seven review candidates (`withConsoleFallback`, `UNMATCHED_ROUTE`,
`HTTP_ERROR`, `VALIDATION_ERROR`, `TransportMismatchError`,
`isAsyncIterable`, `buildOpenApi`) stay as they are.
CHANGELOG: `### Added` for the types, `### Changed` for the mesh tag, and
a new `### Deprecated` for `Headers`. No `### Breaking`.
test/types/public-surface.test.ts fails to compile if any of the new
names stops being exported. `deno publish --dry-run` passes.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Before a peer's hello is accepted, `boundInbound` refuses any frame over
64 KiB, but only once it has the whole frame. On Node, the control
channel's `WebSocketServer` takes the authenticated bound as its
`maxPayload` (about 7 MB at the defaults, so an RPC body fits), and
`maxPayload` is fixed per server. So `ws` assembled a frame up to that
size for a peer that had not yet authenticated. Found in the second
pre-freeze review. The existing pre-auth tests use a fake socket and
never reached `ws`'s own limit.
The Node adapter now counts the raw socket bytes from the upgrade until
the hello is accepted (`boundInbound` gains an `onWiden` hook for that
moment). Past a hello's worth (64 KiB + 1 KiB), it sends close 1009, as
every runtime does for an oversized frame, pauses the socket so `ws`
reads nothing more, and ends it. The counter is installed in the
`handleUpgrade` callback, after `ws` attaches its own `data` listener,
so no chunk is lost.
Bun and Deno have no per-socket limit for this. The CHANGELOG #120 entry
now says so, and says to limit frame size at the proxy if untrusted
peers can reach a Bun or Deno teapot's control path.
Test: a raw client announces a 5 MB frame before its hello and sends
200 KiB of it. The teapot answers with a 1009 close frame and closes the
connection. Without the fix it waits for the rest of the frame.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
#152 made each mesh RPC send wait for `drained()`, but each one waited on
its own. A drain on a backed-up socket releases every waiter at once
(`nodeSocket` keeps them in one list), so they all sent and the buffer
overshot the 1 MiB mark by one frame per concurrent RPC: bounded, but not
what #152 claims. Found in the second pre-freeze review.
`sendWhenDrained` (ws-core, internal) chains sends per socket, and each
one waits for `drained()` when its turn comes. The buffer then peaks at
the mark plus one frame, however many RPCs wait, and frames go out in
call order. The teapot's `reply` and the link's `sendRpc` both use it.
The frame is built at send time, so a call that timed out while queued
sends nothing, and nothing is sent after the close.
Tests: a burst of five 100-byte frames behind a backed-up socket sends
one frame per drain, in order, with the buffer at most one frame. It
fails when each sender waits on its own. Also: a withdrawn frame is
skipped, and a frame queued at close is dropped.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
T2 sent a 1,000,001-byte body against the 1 MB default. The teacup answers
413 with `connection: close` while the client is still uploading, so the
client sometimes saw EPIPE instead of the 413: about 1 run in 10, on
develop too. That is the transport racing the answer, not a different
answer.
Run it against a 1,000-byte limit, the way the edge suite already does.
CARD-24's T2 asks only for "body > maxBodyBytes". 0 failures in 30 runs,
against 2 in 20 before.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
`listen()` awaited `server.listen(port, cb)` without an `error` listener.
A bind failure (EADDRINUSE, EACCES) never calls the callback, so the
promise hung and the error went unhandled. That is the 30 s timeout #138
saw on CI: owner.test.ts reserved a port with `freePort()` (listen on 0,
close, reuse the number), another process on the shared runner took it,
and the teapot's `listen` hung instead of failing.
- core: `bind()` rejects on the `error` event. On failure `server` goes
back to undefined, so `close()` resolves and `listen()` can retry.
- owner.test.ts: lifetime A listens on port 0 directly, since its teapot
is up before the teacup needs the port. Lifetime B has to boot its
teacup against a port nobody holds yet, so it keeps `freePort()` and
reruns on a fresh port on EADDRINUSE, up to three times.
Tests: listen on a taken port rejects with EADDRINUSE, then the same app
listens on 0 and serves; close() after a failed listen resolves. Both
hung without the fix.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Every static file now goes out with `Cache-Control: no-cache`, where
before it sent no Cache-Control at all. A browser or proxy that reused
static files for a lifetime guessed from `Last-Modified` now revalidates
each one, and keeping the old behaviour needs a config change (`static:
{ cacheControl }`). That is a breaking change, so the entry moves from
`### Changed` to `### Breaking`, word for word.
D12 had filed it under `### Changed`. CARD-22's gate table already said
a breaking entry was due if the default turned on, and it did. The
pre-freeze review flagged the mismatch.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
CARD-26 made the WebSocket route pump await `drained()` before each pull,
but mesh RPC traffic sends outside that pump, so it never waited:
- teapot: `handleRpc` runs concurrently per rpc-req, so a teacup that
keeps sending requests and stops reading grows the teapot's buffer by
one response each.
- link: `sendRpc` sent each rpc-req at once, whatever the buffer held.
Both now wait for `drained()` before sending. The teapot drops a response
whose socket closed while waiting. The link starts its timeout before
waiting, so a teapot that stops reading still answers 504, and a call
that settles while waiting (timeout or close) is never sent late.
Found in the pre-freeze integrated review.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
deno.lock records package.json's overrides, so the runtimes (deno) job's
publish dry-run found it out of date after the bump and aborted.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
With `etag: true`, `tagged()` only recognised a handler ETag given as a
string. Given as an array, it compared If-None-Match against the body's
computed tag while sending the handler's array, so a client revalidating
with the tag it was sent got a 200 instead of a 304, and two ETag values
went on the wire.
ETag is single-valued, so the last value of an array wins, as a repeated
`setHeader` would. It is sent alone and drives the comparison.
Found in the pre-freeze integrated review.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
`npm audit --audit-level=moderate` fails on develop: six advisories, all
in devDependencies, none in what ships.
- body-parser (high) and fast-uri (moderate): a plain `npm audit fix`.
- undici (high): the existing override pinned 7.29.1, now inside the
advisory range. Move it to 7.30.1. `--force` wanted a miniflare
downgrade instead.
- multer (high): reached through @nestjs/platform-express, the bench's
Nest comparison. 2.5.0 carries the fix. `--force` wanted a Nest
downgrade, so add an override like the others.
Verified: audit reports 0 vulnerabilities; lint, typecheck, `npm test`
(1149), test:edge (exercises miniflare on the new undici), test:bun,
test:deno and build all pass.
test/mesh/large-body.test.ts T2 fails about 1 run in 10 with EPIPE. That
rate is the same with and without this change (2/20 each), and Node's
fetch uses its bundled undici, not this one. Tracked separately.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The outbound pump pulled a @Ws handler's iterator as fast as it yielded,
whatever the peer read. With a slow client, 10,000 frames of 64 KiB were
all pulled at once and sat in the send buffer: 640 MiB.
WsSocket gains one optional member, drained(): it resolves once the
socket's send buffer is at or below the adapter's high-water mark
(WS_HIGH_WATER_MARK, 1 MiB, internal), or the socket has closed. The
pump awaits it before each pull, so the buffer peaks at the mark plus
one frame. A close ends the wait and the abort path runs the iterator's
return(), as before. A socket without drained() is never waited on.
Per runtime:
- Node: ws.bufferedAmount, released by each send's write callback;
- Bun: getBufferedAmount(), released by the server's drain callback;
- Deno: polls bufferedAmount every 10 ms, only while over the mark;
- workerd reports no buffered amount, so the edge never waits.
The Deno poll also waits while the socket is CONNECTING. Deno hands the
socket over before it opens, and a handler that yielded at once had its
first value pulled into a socket that was not open yet. The pump then
gave up, so the client saw no frame and a 1005 close.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
boundInbound(socket, meshBounds) runs before ensureBooted() and before
the hello is checked, and meshBounds allowed 4,096 queued frames of up
to 7 MB each. During a slow boot nothing reads that queue, so an
unauthenticated peer could make the process buffer tens of GB.
The control channel's bounds are now phased (controlBounds() replaces
controlLimits()):
- until the hello is accepted: frames of at most HELLO_FRAME_BYTES
(64 KiB) and the default 16-frame queue, so about 1 MiB per
connection;
- after: the frame bound from #120 and the queue bound from #148.
boundInbound takes the second set as an optional `widened` argument and
keeps the switch on the bounded socket under a Symbol.for key. The
teapot calls widenInbound() when the handshake succeeds. The teapot's
own parse check follows the same phases, so a standalone
createMeshControl also refuses a pre-auth frame over hello size.
This is an auth-phased bound rather than a total-bytes cap: the only
unauthenticated frame with a purpose is the hello, and phasing keeps
the trusted path free of a second accounting rule. No new option.
On Node the control path's native maxPayload stays at the authed bound,
because ws cannot change it per phase. A pre-auth peer can still make
ws assemble one frame of up to that size before boundInbound closes
the connection with 1009. That frame is transient and never queued.
Tests: during a delayed boot, a 1 MB pre-auth frame closes 1009 at once
and a flood closes 1013 within 17 frames; after the hello, large frames
and a 64-ping burst are accepted. On Node, Deno and Bun, an
unauthenticated 1 MB frame over a real socket closes 1009. The #148
64-RPC test stays green.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
A 999,000-byte text/plain body of U+0001, within maxBodyBytes, still
failed 503: the envelope carries a text body as a JSON string, each
control character escapes to six characters, and the ~6 MB frame was
over the 4,000,000 the channel was sized to.
controlFrameLimit() is now 6 x maxBodyBytes plus 1 MiB for headers,
params, query and the envelope: 7,048,576 at the 1 MB default. Six is
the worst growth of any body byte; quotes and backslashes double, JSON
numbers like 1e20 grow about fivefold, multipart Buffers at most
fourfold, and non-ASCII text is not escaped. The fixed MAX_FRAME_CHARS
goes away with it.
Test (T1c) on Node, Deno and Bun: the control-character body now
answers 200 and the channel stays open.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The control channel also inherited limits.maxWsQueue (16 undelivered
frames, close 1013) from #107. On Node, ws emits every frame of one
socket read synchronously, so a teacup with more than 16 RPCs in flight
sent a burst the teapot's queue refused: the link dropped and every
pending request failed 503. Deno and Bun deliver one frame per task and
did not trip.
controlLimits() now also raises maxWsQueue for the control channel, to
an internal 4,096 frames or maxWsQueue if larger, alongside the size
bound from #120. The teapot's frame loop never awaits between frames, so
the queue only holds one delivery burst, and one read (at most 64 KiB)
holds fewer than 4,096 of the smallest control frame. The bound stays
finite, so a peer flooding a channel nobody is reading is still cut off.
No new option. User @Ws routes keep closing 1013 at maxWsQueue.
Tests: 64 RPCs in one tick through app.fetch on one link all answer 200
(red on Node before), and a user route on the same teapot still closes
1013, on Node, Deno and Bun.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The 1 MiB inbound cap from #107 applied to every WebSocket, the mesh
control channel included. An RPC carries a whole request body, so a body
inside maxBodyBytes could still overflow the cap once wrapped in an
rpc-req frame, and the teapot then closed the whole channel with 1009:
every request through that link failed 503 until it reconnected.
The test asked for by the card (T1, a 1 MB JSON body at defaults) passes
on Node, Deno and Bun, because a JSON body re-encodes to about its own
size. Two other cases fail on all three before this change:
- T1b: a 999 KB text body of quotes doubles under JSON escaping;
- T4: maxBodyBytes raised to 4 MB, a 3.9 MB JSON body.
The control channel's bound is now derived from the teapot's
limits.maxBodyBytes via controlFrameLimit(): MAX_FRAME_CHARS (4,000,000)
at the 1 MB default, scaled by the same ratio above it, never below
maxWsMessageBytes. No new option. User @Ws routes keep
maxWsMessageBytes: Node gets a second WebSocketServer for the control
path, app.upgrade picks the bound from the path before subscribing, and
Bun's single native maxPayloadLength is raised on a teapot only, leaving
app.upgrade to close user routes 1009 itself.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Text responses went out uncompressed unless a proxy sat in front of every
runtime. createApp({ compression: true | { threshold, encodings } }), off
by default, implements D13 strategy B as accepted on 2026-10-22.
- One function, compressOutcome, runs after handle() and before either
adapter writes, so Node and the fetch runtimes cannot diverge.
- Accept-Encoding negotiation with q-values, identity, * and q=0; ties go
to server preference (br before gzip). Vary: Accept-Encoding is merged
wherever the request decided the outcome, including every 304. Skips:
existing Content-Encoding or Content-Range, no or an incompressible
Content-Type (ndjson is compressible), Cache-Control: no-transform.
HEAD and bodies under threshold keep Vary; 204 gets none.
- Node, Deno, Bun: node:zlib only, loaded lazily through nodeRequire.
Buffered bodies use the async API, never the sync one; br at quality 4.
Content-Length is dropped from an encoded body.
- Streams (SSE, ndjson): a zlib stream flushed after every frame, error
frame and ping, piped into res on Node and wrapped around the
ReadableStream on fetch runtimes. Backpressure follows the compressor;
a client leaving destroys it.
- Edge: core never encodes and sets Vary only. Edge is recognised by
edgeHandler, which marks the app through an internal symbol, and by
createApp detecting workerd (navigator.userAgent, or node:zlib failing
to load), which covers a bare app.fetch export.
- ETags from CARD-15 are taken on the identity body and stay weak, so the
tag does not change with the coding.
Deno runs zlib's async API on the main thread; that is documented and
pinned by a test, not worked around.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Conditional GETs were never answered: every revalidation re-downloaded
the file or response.
- Static (D12, always on): a hit carries W/"<size>-<mtimeMs base36>",
Last-Modified and Cache-Control from the stat the resolver already did.
A matching If-None-Match, or If-Modified-Since when If-None-Match is
absent, answers 304 before the file is read. StaticHit now carries the
stat and a read() for the bytes, and HEAD no longer reads either.
- static: { dir?, cacheControl? } (rule 1a): Cache-Control defaults to
no-cache so browsers revalidate rather than reuse a file for a lifetime
guessed from Last-Modified. An unknown key or CR/LF throws at boot.
- createApp({ etag: true }) (off by default, boolean only): a buffered 200
to GET/HEAD gets a weak tag from a 32-bit FNV-1a hash of its UTF-8 bytes
plus its length, computed before HEAD blanks the body. A handler-set
etag is kept and only compared. Weak comparison, lists split outside
quotes, and * are supported.
- Every buffered 304 leaves dispatch bodiless, with its content-* headers
dropped, so NotModified matches the ETag path on every adapter.
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>