FPRD-001a batch 1: core safety and adapter correctness. One commit per issue, cherry-picked from per-card lanes; CHANGELOG [Unreleased] sections merged.
serveDeno/serveBun populate ctx.ip with the socket peer; trustProxy + no XFF now falls back to the peer, as on Node.
Gates (integrated branch)
lint 0 errors (50 warnings, 48 pre-existing no-explicit-any, 2 new in ws.ts following that file's style) · format · typecheck · npm test 646/646 · complexity · build · test:deno 34 passed · test:bun 24 pass · test:edge PASS · npm audit --omit=dev 0.
Deviations from the cards — please review
#107 on Bun closes 1006, not 1009. Bun drops the connection without a close frame when maxPayloadLength is exceeded (verified on Bun 1.3.14). The pre-buffer cap is kept as D1 requires; 1006 is documented in JSDoc/README/CHANGELOG and asserted in the Bun test. D1 needs amending to accept this.
#107: a route that never reads inbound is now closed with 1013 after 17 messages (Node used to drop them; other runtimes buffered unboundedly). In the Breaking entry.
#107 / #116 use Symbol.for globals. tsup emits index, deno, bun without a shared chunk, so module-private state is duplicated per entry. #116's card design (module WeakMap) left ctx.ip empty in the built @green-tea/core/bun; verified against dist/.
#104: the crash only occurred on routes with a param segment; fixed paths silently disconnected. Also fixed eventSocket (ws-adapter.ts) so a close before open on Deno is not lost.
#108: two card claims did not hold — a throwing cors.origins is already caught (originAllowed), and an NDJSON encoder throw is caught in pipeStream. Both kept as regression tests; the "after headers" case is covered by an iterator that throws on creation.
#106: resolver split into two helpers (complexity 31 > 25 inline); a missing root is not cached as a miss, so a public/ created after boot still serves. Deno tests use committed symlink fixtures (suite runs without --allow-write); not published.
#105: counting-stream fixture uses highWaterMark 0; runtime socket tests use a 1000-byte limit (workerd sometimes reset the connection mid-upload with MB bodies).
Open items, not in this PR
Companion docs PR (green-tea-docs) for the new WS options, static 404 semantics, missing request:end on listener failures.
#116 cross-repo evidence: plugins rate-limit regression (T9) was run against a built core in a scratch copy and passed on Deno and Bun; it still needs its own PR in green-tea-plugins. Matcha starter smoke (T12) not run.
Mesh RPC frames now fall under the 1 MiB default; untested near maxBodyBytes.
Follow-ups worth issues: busboy maxParts off-by-one (N parts rejected); edge HTTP ignores cf-connecting-ip; intermittent mesh test timeouts (heartbeat, integration) seen ~1/25 runs.
Dev-only npm audit advisories (16, pre-existing on develop) left for a separate PR.
FPRD-001a batch 1: core safety and adapter correctness. One commit per issue, cherry-picked from per-card lanes; CHANGELOG `[Unreleased]` sections merged.
| Commit | Issue | Change |
|---|---|---|
| `fix(views)` | #106 | Static serving confined to the root's **real** path. Out-of-root and dangling symlinks are a 404 (D3), not 403. |
| `fix(http)` | #108 | Node listener catches rejections: 500 + `connection: close` while writable (no `onError` re-entry), socket destroyed otherwise (D2). |
| `fix(ws)` | #104 | Malformed upgrades get a written 400 / unknown routes 404 instead of crashing; Deno/Bun/edge close `1008`. |
| `feat(ws)!` | #107 | `limits.maxWsMessageBytes` (1 MiB) and `limits.maxWsQueue` (16), validated at boot; close `1009` / `1013` (D1). **Breaking.** |
| `fix(http)` | #105 | Fetch runtimes enforce `maxBodyBytes` while streaming; declared oversized `Content-Length` refused without reading (Node too). |
| `fix(runtime)` | #116 | `serveDeno`/`serveBun` populate `ctx.ip` with the socket peer; `trustProxy` + no XFF now falls back to the peer, as on Node. |
## Gates (integrated branch)
lint 0 errors (50 warnings, 48 pre-existing `no-explicit-any`, 2 new in `ws.ts` following that file's style) · format · typecheck · `npm test` 646/646 · complexity · build · `test:deno` 34 passed · `test:bun` 24 pass · `test:edge` PASS · `npm audit --omit=dev` 0.
## Deviations from the cards — please review
- **#107 on Bun closes `1006`, not `1009`.** Bun drops the connection without a close frame when `maxPayloadLength` is exceeded (verified on Bun 1.3.14). The pre-buffer cap is kept as D1 requires; `1006` is documented in JSDoc/README/CHANGELOG and asserted in the Bun test. D1 needs amending to accept this.
- **#107:** a route that never reads `inbound` is now closed with `1013` after 17 messages (Node used to drop them; other runtimes buffered unboundedly). In the Breaking entry.
- **#107 / #116 use `Symbol.for` globals.** tsup emits `index`, `deno`, `bun` without a shared chunk, so module-private state is duplicated per entry. #116's card design (module `WeakMap`) left `ctx.ip` empty in the built `@green-tea/core/bun`; verified against `dist/`.
- **#104:** the crash only occurred on routes with a param segment; fixed paths silently disconnected. Also fixed `eventSocket` (`ws-adapter.ts`) so a close before `open` on Deno is not lost.
- **#108:** two card claims did not hold — a throwing `cors.origins` is already caught (`originAllowed`), and an NDJSON encoder throw is caught in `pipeStream`. Both kept as regression tests; the "after headers" case is covered by an iterator that throws on creation.
- **#106:** resolver split into two helpers (complexity 31 > 25 inline); a missing root is not cached as a miss, so a `public/` created after boot still serves. Deno tests use committed symlink fixtures (suite runs without `--allow-write`); not published.
- **#105:** counting-stream fixture uses highWaterMark 0; runtime socket tests use a 1000-byte limit (workerd sometimes reset the connection mid-upload with MB bodies).
## Open items, not in this PR
- Companion docs PR (green-tea-docs) for the new WS options, static 404 semantics, missing `request:end` on listener failures.
- #116 cross-repo evidence: plugins rate-limit regression (T9) was run against a built core in a scratch copy and passed on Deno and Bun; it still needs its own PR in green-tea-plugins. Matcha starter smoke (T12) not run.
- Mesh RPC frames now fall under the 1 MiB default; untested near `maxBodyBytes`.
- Follow-ups worth issues: busboy `maxParts` off-by-one (N parts rejected); edge HTTP ignores `cf-connecting-ip`; intermittent mesh test timeouts (`heartbeat`, `integration`) seen ~1/25 runs.
- Dev-only `npm audit` advisories (16, pre-existing on develop) left for a separate PR.
The static resolver's traversal guard compared paths lexically, and the
read that followed it resolved symlinks, so a link inside the root such
as `public/leak -> /etc/hosts` served a file outside it.
Containment now compares real paths. The root's real path is resolved
on the first request and cached (a failed lookup is not, so a root
created after boot still starts serving); the requested file and a
directory's `index.html` are each realpath'd and must lie at or beneath
it, with the `root + sep` rule keeping a sibling such as `root-evil`
out. The lexical guard stays in front, since it rejects `..` without a
syscall.
An escape or a dangling link is a plain miss: 404 through `onError`, or
405/204 where the path has routes. Not 403, so a probe cannot tell a
file outside the root from one that does not exist. Re-pointing a root
symlink at runtime needs a restart. The realpath-to-read race is left
open and marked; closing it needs per-component O_NOFOLLOW, which is
not portable across Node, Deno and Bun.
Closes#106
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The Node request listener was an async function, and http.createServer
ignores the promise a listener returns. Anything that rejected outside
the region where errors convert to a response - a custom static resolver,
a handler header value Node refuses to write (ERR_INVALID_CHAR), a stream
that fails between flushing its headers and its first frame - became an
unhandled rejection, which Node's default mode turns into a process exit.
The listener now hands the request to serve() and catches its rejection
in failSafe(), per refinement decision D2:
- writable: a fixed 500 with connection: close, written through the
patched writeHead so the security headers still land, without calling
onError again;
- headers or body already sent, or the client gone: destroy the socket;
- the failure is logged through logger.error first, guarded, with
String(err) for non-Error values.
No request:end is emitted for these requests: observers do not alter the
response, and the core never completed it. The request gate slot is
already released by the existing finally, which the tests prove.
Deno, Bun and the edge are unaffected: they receive app.fetch's promise
and the runtime answers a rejection itself.
Closes#108
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The Node 'upgrade' listener matched the raw request path without the
normalization HTTP runs. A bad percent escape in a param segment threw
URIError synchronously inside the listener, an uncaught exception that
ends the process, and '//' silently matched a route HTTP refuses.
Upgrades now normalize the path first: malformed escapes and repeated
slashes get a 400, an unknown route a written 404 instead of a bare
destroy, and any other throw in the listener a 500. app.upgrade
(Deno/Bun/edge) closes 1008 'invalid request path' rather than 1011.
On Deno the adapter's socket is still CONNECTING when an early 1008 is
sent, and that close was a no-op that left the peer hanging; eventSocket
now defers such a close to 'open'.
Closes#104
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Inbound WebSocket traffic was unbounded per connection: Node used ws's
100 MiB default payload, the other runtimes had no cap of their own, and
the queue behind `inbound` was an unbounded channel on every runtime, so
one client could exhaust memory with large messages or a slow consumer.
Add `limits.maxWsMessageBytes` (default 1 MiB, close 1009) and
`limits.maxWsQueue` (default 16 unread messages, close 1013), as recorded
in D1. Both are server-wide and validated by createApp, which throws a
TypeError for anything but a positive integer. Enforcement is shared in
`boundInbound`, which subscribes immediately and replaces the
subscribe-before-boot trick in app.upgrade. Node and Bun also get the
native pre-buffer cap; Bun drops the connection without a close frame,
so its peer sees 1006, which is documented and tested. Deno and workerd
expose no such option and check the size after receipt.
BREAKING CHANGE: messages over 1 MiB now close the connection with 1009,
and a connection with 16 unread inbound messages is closed with 1013 on
the next one, including a handler that never reads `inbound`.
Closes#107
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The fetch adapter read every body through request.arrayBuffer() and
compared the length afterwards, so Deno, Bun and the edge buffered an
oversized upload in full before refusing it. readFetchBytes now reads
request.body chunk by chunk, stops at the chunk that crosses the limit
and cancels the reader, so no further chunk is pulled.
A content-length that already declares more than the limit is refused
before anything is read, on both adapters. On Node the request used to
wait for its first chunk, which a client that sends only headers never
delivers. A malformed or absent header is ignored and the running count
enforces the limit. The response is the same 413 through onError, and
the route-over-server precedence for maxBodyBytes and maxParts is
untouched; the new tests pin it.
The over-read is proven with a counting stream rather than a status
code, which is the same 413 either way. The stream uses a high-water
mark of 0: the default of 1 pulls a chunk at construction, before any
reader exists, which would make "nothing was read" unprovable.
Socket-level tests on Deno, Bun and workerd use a 1000-byte route limit
so every refused body fits in the socket buffer. With a multi-megabyte
body the client is still writing when the 413 lands and sometimes sees
ECONNRESET instead, which is the transport racing the answer. The Bun
socket test also disables keep-alive: Bun's own fetch client reuses a
socket after a response that arrived before the body was read, and its
next request on it comes back 400 or 431. Node's fetch against the same
Bun server does not.
Closes#105
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
buildFetch had no channel for a peer address, so ctx.ip was '' for
every HTTP request served by serveDeno or serveBun unless trustProxy and
x-forwarded-for supplied one. Everything keyed on the address shared one
value: the rate-limit plugin put every client in a single bucket, and
one client could exhaust the limit for all of them.
The adapters now record the peer in a WeakMap keyed by the Request
object (src/http/peer.ts, not exported) and pass that same object to
app.fetch. A header would be visible to handlers and spoofable; a second
fetch parameter would be public API. buildFetch derives ctx.ip as Node's
deriveIp does: the first x-forwarded-for hop when trustProxy is on and
the header is present, the peer otherwise. trustProxy without the header
therefore falls back to the peer instead of answering ''.
The map hangs off globalThis under Symbol.for('@green-tea/core:peer')
rather than living in the module. tsup's CommonJS build bundles index,
deno and bun as separate files with no shared chunk, so each gets its
own copy of peer.ts; with a module-private map, serveBun from
@green-tea/core/bun recorded peers that app.fetch from @green-tea/core
never saw, and ctx.ip stayed ''. A test loads a second instance of the
module to pin this.
A bare app.fetch from user code, or a Request copied from the adapter's,
has no entry and answers exactly what it did before. Addresses are
passed through unnormalised. WebSocket and the edge adapter are
unchanged; trusting cf-connecting-ip is a separate decision.
Closes#116
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
What this change does: adds bounds and safety checks across static serving, HTTP body reads, WebSocket handling, and runtime adapters. Must fix before merge: src/http/ws-core.ts:83-84,113-119 returns the same InboundFifo for every @inbound() iterator, and a second pending next() overwrites the first waiter. A handler with two consumers waiting for one frame hangs one consumer forever; sequential consumers split frames instead of receiving the previous channel's fan-out. I reproduced the hang on PR head f78c9dc with two iterators and one pushed frame. Preserve bounded fan-out for each subscriber, or explicitly reject a second consumer as a documented breaking change; add a two-consumer regression test. The 89 focused tests passed but cover only one consumer. Verdict: fix this before merge.
What this change does: adds bounds and safety checks across static serving, HTTP body reads, WebSocket handling, and runtime adapters. Must fix before merge: `src/http/ws-core.ts:83-84,113-119` returns the same `InboundFifo` for every `@inbound()` iterator, and a second pending `next()` overwrites the first `waiter`. A handler with two consumers waiting for one frame hangs one consumer forever; sequential consumers split frames instead of receiving the previous channel's fan-out. I reproduced the hang on PR head f78c9dc with two iterators and one pushed frame. Preserve bounded fan-out for each subscriber, or explicitly reject a second consumer as a documented breaking change; add a two-consumer regression test. The 89 focused tests passed but cover only one consumer. Verdict: fix this before merge.
boundInbound returned one shared FIFO to every `inbound` iterator, with a
single waiter slot. Two consumers waiting at once left one hanging forever,
sequential consumers split frames, and one consumer's return() ended the
stream for all. Node used to fan out through `channel`; Deno, Bun and edge
already shared one iterator before #107, so the bug was older there.
Each iterator now gets its own queue, and maxWsQueue bounds each one. Frames
that arrive before anyone reads still go to the first consumer, which keeps
the mesh `hello`.
Refs #107
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Fixed in 7fa02d1. boundInbound now gives each inbound iterator its own queue, and maxWsQueue bounds each queue. One consumer's return() no longer ends the others. Frames that arrive before anyone reads still go to the first consumer, so the mesh hello is kept.
Note: Deno, Bun and edge already shared a single iterator before this PR, because of the old subscribe-before-boot trick in buildAppUpgrade. Only Node was regressed by #107, and this fix restores fan-out on every runtime.
Regression tests in test/ws-limits.test.ts, all three failing before the fix:
two consumers waiting at once both receive the frame (this test hung)
after one consumer returns, the next one still receives frames
a consumer that subscribes and never reads triggers 1013
Fixed in 7fa02d1. `boundInbound` now gives each `inbound` iterator its own queue, and `maxWsQueue` bounds each queue. One consumer's `return()` no longer ends the others. Frames that arrive before anyone reads still go to the first consumer, so the mesh `hello` is kept.
Note: Deno, Bun and edge already shared a single iterator before this PR, because of the old subscribe-before-boot trick in `buildAppUpgrade`. Only Node was regressed by #107, and this fix restores fan-out on every runtime.
Regression tests in `test/ws-limits.test.ts`, all three failing before the fix:
- two consumers waiting at once both receive the frame (this test hung)
- after one consumer returns, the next one still receives frames
- a consumer that subscribes and never reads triggers `1013`
Gates re-run: `npm test` 649/649 · test:deno 34 · test:bun 24 · test:edge PASS · lint/format/typecheck/complexity/build clean.
Follow-up review of 7fa02d1: the original two-consumer hang is fixed. Two gaps remain. (1) Must fix — src/http/ws-core.ts:138-142: accept() offers a frame to subscribers in order, then discovers a later subscriber's queue is full and closes 1013. With maxWsQueue=1, a fast and a stalled subscriber, the overflow frame was delivered to the fast subscriber while the slow one never received it. This lets a rejected frame trigger only some handler side effects. Check all subscriber capacity before delivering the frame, and test that the overflow frame reaches none. (2) Must fix — src/http/ws-core.ts:106-110 and src/http/ws.ts's nodeSocket: the bound check runs in an async pump after the unbounded channel() has accepted frames. The installed Node ws server emits messages synchronously by default; 100,000 synchronous pushes produced no close until the event loop yielded, then 1013. Enforce the bound at the synchronous adapter input, before an unbounded queue, and test a burst sent without yielding. All local gates passed at this head: 649 unit tests, Deno 34, Bun 24, edge, lint, format, typecheck, build, complexity, and production audit. Verdict: fix 1 and 2 before merge.
Follow-up review of 7fa02d1: the original two-consumer hang is fixed. Two gaps remain. (1) Must fix — `src/http/ws-core.ts:138-142`: `accept()` offers a frame to subscribers in order, then discovers a later subscriber's queue is full and closes 1013. With maxWsQueue=1, a fast and a stalled subscriber, the overflow frame was delivered to the fast subscriber while the slow one never received it. This lets a rejected frame trigger only some handler side effects. Check all subscriber capacity before delivering the frame, and test that the overflow frame reaches none. (2) Must fix — `src/http/ws-core.ts:106-110` and `src/http/ws.ts`'s `nodeSocket`: the bound check runs in an async pump after the unbounded `channel()` has accepted frames. The installed Node `ws` server emits messages synchronously by default; 100,000 synchronous pushes produced no close until the event loop yielded, then 1013. Enforce the bound at the synchronous adapter input, before an unbounded queue, and test a burst sent without yielding. All local gates passed at this head: 649 unit tests, Deno 34, Bun 24, edge, lint, format, typecheck, build, complexity, and production audit. Verdict: fix 1 and 2 before merge.
Two gaps in boundInbound, both from review of #117.
The bound ran in an async pump reading the adapter's channel. `ws` emits a
whole TCP read's worth of frames synchronously, so the unbounded channel
took the burst before the pump saw the first frame: with maxWsQueue 2, a
2,000-frame burst reached the channel in full before close(1013). boundInbound now taps
the channel through an internal, non-exported hook that runs inside push(),
so each frame is bounded before it is queued. Measured on the Node
listen() path, the same burst now closes on the 3rd frame.
accept() also offered a frame to consumers in order and closed 1013 when a
later queue was full, so the rejected frame had already reached earlier
consumers. Capacity is now checked for every consumer before any delivery.
Refs #107
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
(1) A rejected frame now reaches no consumer.accept() checks every consumer's capacity before delivering to any of them. Test: maxWsQueue: 1 with a fast reader and a stalled one. The overflow frame closes the connection with 1013, and the fast reader's pending next() resolves done without ever seeing the frame.
(2) The bound now applies inside the adapter's synchronous push.channel has an internal hook, CHANNEL_TAP, keyed with Symbol.for and not exported from the package. boundInbound uses it to see each frame inside push() and bound it before anything is queued, instead of reading through an async iterator. Every adapter builds its inbound with channel(), so this covers Node, Deno, Bun and edge. The old async pump is kept only as a fallback for an inbound that isn't a channel; no adapter builds one.
Unit tests: 100,000 synchronous pushes with maxWsQueue: 2 close 1013 before the loop returns, and the size bound closes 1009 synchronously too.
Probe on the real Node listen() path, maxWsQueue: 2, client sending 2,000 frames back to back:
at 7fa02d1, close(1013) was called after 2,000 server-side message events;
Also recorded: D1 amendment. On Bun, a message over the limit closes as 1006 instead of 1009. Bun drops the connection without sending a close frame, and we keep its native cap because it rejects the message before it is buffered. This is already documented in JSDoc, the README and the CHANGELOG.
Both items from review 2 are fixed in 26bacdb.
**(1) A rejected frame now reaches no consumer.** `accept()` checks every consumer's capacity before delivering to any of them. Test: `maxWsQueue: 1` with a fast reader and a stalled one. The overflow frame closes the connection with `1013`, and the fast reader's pending `next()` resolves `done` without ever seeing the frame.
**(2) The bound now applies inside the adapter's synchronous `push`.** `channel` has an internal hook, `CHANNEL_TAP`, keyed with `Symbol.for` and not exported from the package. `boundInbound` uses it to see each frame inside `push()` and bound it before anything is queued, instead of reading through an async iterator. Every adapter builds its `inbound` with `channel()`, so this covers Node, Deno, Bun and edge. The old async pump is kept only as a fallback for an inbound that isn't a channel; no adapter builds one.
- Unit tests: 100,000 synchronous pushes with `maxWsQueue: 2` close `1013` before the loop returns, and the size bound closes `1009` synchronously too.
- Probe on the real Node `listen()` path, `maxWsQueue: 2`, client sending 2,000 frames back to back:
- at 7fa02d1, `close(1013)` was called after 2,000 server-side `message` events;
- at 26bacdb, it is called on the 3rd.
- The remaining frames from that same TCP read are still parsed by `ws`, but they are discarded and not queued.
Gates: `npm test` 652/652 · test:deno 34 · test:bun 24 · test:edge PASS · lint/format/typecheck/complexity/build clean.
Also recorded: **D1 amendment.** On Bun, a message over the limit closes as `1006` instead of `1009`. Bun drops the connection without sending a close frame, and we keep its native cap because it rejects the message before it is buffered. This is already documented in JSDoc, the README and the CHANGELOG.
Follow-up verification on PR head 26bacdb: both findings from review 2 are resolved. (1) InboundFanout.accept() checks every subscriber for capacity before offering a frame, and the regression test confirms an overflow frame reaches neither the fast nor the stalled subscriber. (2) CHANNEL_TAP runs the bound inside adapter channel.push(), before the unbounded async channel can queue a burst. I repeated the real loopback createHttpServer probe with maxWsQueue: 2 and 2,000 frames in one write: close(1013) was called at frame 3 (previous head: frame 2,000). The remaining ws message events were parsed but not queued by Green Tea. Verified locally: 652 unit tests, Deno 34, Bun 24, edge, lint, format, typecheck, build, complexity, production audit (0 advisories), and clean diff. These two review findings are closed; this comment does not assess the separate PR open items.
Follow-up verification on PR head 26bacdb: both findings from review 2 are resolved. (1) `InboundFanout.accept()` checks every subscriber for capacity before offering a frame, and the regression test confirms an overflow frame reaches neither the fast nor the stalled subscriber. (2) `CHANNEL_TAP` runs the bound inside adapter `channel.push()`, before the unbounded async channel can queue a burst. I repeated the real loopback `createHttpServer` probe with `maxWsQueue: 2` and 2,000 frames in one write: `close(1013)` was called at frame 3 (previous head: frame 2,000). The remaining `ws` message events were parsed but not queued by Green Tea. Verified locally: 652 unit tests, Deno 34, Bun 24, edge, lint, format, typecheck, build, complexity, production audit (0 advisories), and clean diff. These two review findings are closed; this comment does not assess the separate PR open items.
chrnx
merged commit 4d1639f7c5 into develop2026-10-10 16:49:36 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
FPRD-001a batch 1: core safety and adapter correctness. One commit per issue, cherry-picked from per-card lanes; CHANGELOG
[Unreleased]sections merged.fix(views)fix(http)connection: closewhile writable (noonErrorre-entry), socket destroyed otherwise (D2).fix(ws)1008.feat(ws)!limits.maxWsMessageBytes(1 MiB) andlimits.maxWsQueue(16), validated at boot; close1009/1013(D1). Breaking.fix(http)maxBodyByteswhile streaming; declared oversizedContent-Lengthrefused without reading (Node too).fix(runtime)serveDeno/serveBunpopulatectx.ipwith the socket peer;trustProxy+ no XFF now falls back to the peer, as on Node.Gates (integrated branch)
lint 0 errors (50 warnings, 48 pre-existing
no-explicit-any, 2 new inws.tsfollowing that file's style) · format · typecheck ·npm test646/646 · complexity · build ·test:deno34 passed ·test:bun24 pass ·test:edgePASS ·npm audit --omit=dev0.Deviations from the cards — please review
1006, not1009. Bun drops the connection without a close frame whenmaxPayloadLengthis exceeded (verified on Bun 1.3.14). The pre-buffer cap is kept as D1 requires;1006is documented in JSDoc/README/CHANGELOG and asserted in the Bun test. D1 needs amending to accept this.inboundis now closed with1013after 17 messages (Node used to drop them; other runtimes buffered unboundedly). In the Breaking entry.Symbol.forglobals. tsup emitsindex,deno,bunwithout a shared chunk, so module-private state is duplicated per entry. #116's card design (moduleWeakMap) leftctx.ipempty in the built@green-tea/core/bun; verified againstdist/.eventSocket(ws-adapter.ts) so a close beforeopenon Deno is not lost.cors.originsis already caught (originAllowed), and an NDJSON encoder throw is caught inpipeStream. Both kept as regression tests; the "after headers" case is covered by an iterator that throws on creation.public/created after boot still serves. Deno tests use committed symlink fixtures (suite runs without--allow-write); not published.Open items, not in this PR
request:endon listener failures.maxBodyBytes.maxPartsoff-by-one (N parts rejected); edge HTTP ignorescf-connecting-ip; intermittent mesh test timeouts (heartbeat,integration) seen ~1/25 runs.npm auditadvisories (16, pre-existing on develop) left for a separate PR.buildFetch had no channel for a peer address, so ctx.ip was '' for every HTTP request served by serveDeno or serveBun unless trustProxy and x-forwarded-for supplied one. Everything keyed on the address shared one value: the rate-limit plugin put every client in a single bucket, and one client could exhaust the limit for all of them. The adapters now record the peer in a WeakMap keyed by the Request object (src/http/peer.ts, not exported) and pass that same object to app.fetch. A header would be visible to handlers and spoofable; a second fetch parameter would be public API. buildFetch derives ctx.ip as Node's deriveIp does: the first x-forwarded-for hop when trustProxy is on and the header is present, the peer otherwise. trustProxy without the header therefore falls back to the peer instead of answering ''. The map hangs off globalThis under Symbol.for('@green-tea/core:peer') rather than living in the module. tsup's CommonJS build bundles index, deno and bun as separate files with no shared chunk, so each gets its own copy of peer.ts; with a module-private map, serveBun from @green-tea/core/bun recorded peers that app.fetch from @green-tea/core never saw, and ctx.ip stayed ''. A test loads a second instance of the module to pin this. A bare app.fetch from user code, or a Request copied from the adapter's, has no entry and answers exactly what it did before. Addresses are passed through unnormalised. WebSocket and the edge adapter are unchanged; trusting cf-connecting-ip is a separate decision. Closes #116 Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>What this change does: adds bounds and safety checks across static serving, HTTP body reads, WebSocket handling, and runtime adapters. Must fix before merge:
src/http/ws-core.ts:83-84,113-119returns the sameInboundFifofor every@inbound()iterator, and a second pendingnext()overwrites the firstwaiter. A handler with two consumers waiting for one frame hangs one consumer forever; sequential consumers split frames instead of receiving the previous channel's fan-out. I reproduced the hang on PR headf78c9dcwith two iterators and one pushed frame. Preserve bounded fan-out for each subscriber, or explicitly reject a second consumer as a documented breaking change; add a two-consumer regression test. The 89 focused tests passed but cover only one consumer. Verdict: fix this before merge.Fixed in
7fa02d1.boundInboundnow gives eachinbounditerator its own queue, andmaxWsQueuebounds each queue. One consumer'sreturn()no longer ends the others. Frames that arrive before anyone reads still go to the first consumer, so the meshhellois kept.Note: Deno, Bun and edge already shared a single iterator before this PR, because of the old subscribe-before-boot trick in
buildAppUpgrade. Only Node was regressed by #107, and this fix restores fan-out on every runtime.Regression tests in
test/ws-limits.test.ts, all three failing before the fix:1013Gates re-run:
npm test649/649 · test:deno 34 · test:bun 24 · test:edge PASS · lint/format/typecheck/complexity/build clean.Follow-up review of
7fa02d1: the original two-consumer hang is fixed. Two gaps remain. (1) Must fix —src/http/ws-core.ts:138-142:accept()offers a frame to subscribers in order, then discovers a later subscriber's queue is full and closes 1013. With maxWsQueue=1, a fast and a stalled subscriber, the overflow frame was delivered to the fast subscriber while the slow one never received it. This lets a rejected frame trigger only some handler side effects. Check all subscriber capacity before delivering the frame, and test that the overflow frame reaches none. (2) Must fix —src/http/ws-core.ts:106-110andsrc/http/ws.ts'snodeSocket: the bound check runs in an async pump after the unboundedchannel()has accepted frames. The installed Nodewsserver emits messages synchronously by default; 100,000 synchronous pushes produced no close until the event loop yielded, then 1013. Enforce the bound at the synchronous adapter input, before an unbounded queue, and test a burst sent without yielding. All local gates passed at this head: 649 unit tests, Deno 34, Bun 24, edge, lint, format, typecheck, build, complexity, and production audit. Verdict: fix 1 and 2 before merge.Both items from review 2 are fixed in
26bacdb.(1) A rejected frame now reaches no consumer.
accept()checks every consumer's capacity before delivering to any of them. Test:maxWsQueue: 1with a fast reader and a stalled one. The overflow frame closes the connection with1013, and the fast reader's pendingnext()resolvesdonewithout ever seeing the frame.(2) The bound now applies inside the adapter's synchronous
push.channelhas an internal hook,CHANNEL_TAP, keyed withSymbol.forand not exported from the package.boundInbounduses it to see each frame insidepush()and bound it before anything is queued, instead of reading through an async iterator. Every adapter builds itsinboundwithchannel(), so this covers Node, Deno, Bun and edge. The old async pump is kept only as a fallback for an inbound that isn't a channel; no adapter builds one.maxWsQueue: 2close1013before the loop returns, and the size bound closes1009synchronously too.listen()path,maxWsQueue: 2, client sending 2,000 frames back to back:7fa02d1,close(1013)was called after 2,000 server-sidemessageevents;26bacdb, it is called on the 3rd.ws, but they are discarded and not queued.Gates:
npm test652/652 · test:deno 34 · test:bun 24 · test:edge PASS · lint/format/typecheck/complexity/build clean.Also recorded: D1 amendment. On Bun, a message over the limit closes as
1006instead of1009. Bun drops the connection without sending a close frame, and we keep its native cap because it rejects the message before it is buffered. This is already documented in JSDoc, the README and the CHANGELOG.Follow-up verification on PR head
26bacdb: both findings from review 2 are resolved. (1)InboundFanout.accept()checks every subscriber for capacity before offering a frame, and the regression test confirms an overflow frame reaches neither the fast nor the stalled subscriber. (2)CHANNEL_TAPruns the bound inside adapterchannel.push(), before the unbounded async channel can queue a burst. I repeated the real loopbackcreateHttpServerprobe withmaxWsQueue: 2and 2,000 frames in one write:close(1013)was called at frame 3 (previous head: frame 2,000). The remainingwsmessage events were parsed but not queued by Green Tea. Verified locally: 652 unit tests, Deno 34, Bun 24, edge, lint, format, typecheck, build, complexity, production audit (0 advisories), and clean diff. These two review findings are closed; this comment does not assess the separate PR open items.