fix(mesh): give the control channel its own inbound queue bound (#148)

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>
This commit is contained in:
chrnx committed 2026-10-23 01:16:43 -05:00
1 parent 713122d53a
commit cad81223e5
5 files changed
+165 -8

No files matched your search

+8
View File
@@ -242,6 +242,14 @@ 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
(`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.
- **Edge HTTP fills `ctx.ip` from `cf-connecting-ip` under `trustProxy`** (#119). `edgeHandler`
never read the header for HTTP, so IP-keyed plugins such as rate-limit saw `''`, one bucket for
every client. Under `trustProxy: true` the header now sets `ctx.ip`, and it wins over