Repository navigation
Description
Summary
A large HTTP response from a bb server that a visitor reads slower than the server sends it piles up in the connect gate's TunnelDO memory. There is no backpressure anywhere on the path. Once roughly 100+ MB is unread, the Durable Object exceeds its memory limit and resets. The download fails, and the server's tunnel drops for everyone using it. The gate needs flow control so that a slow reader slows the server down instead of filling gate memory.
Versions and environment
mainat98706229e4e088b46f1b676280c891f224d4a071: connect gate (apps/connect),@bb/tunnel-client, connect plugin.- Reproduced against the staging gate
bb-connect-staging(*.vibecodethis.site), running main's gate with main's client code.
Steps to reproduce
Reproduced with a lab harness in bb thread thr_j2j7gu9n5f. The harness runs a real connect plugin ConnectTunnel for a staging server and serves a streaming origin from the same process.
-
Pair a bb server with the staging gate. Serve a 400 MB response through it: any endpoint that streams 400 MB with Node's normal
res.write()backpressure toward the tunnel client works. -
Download it through the gate with a slow reader:
curl -s --limit-rate 256k -o /dev/null -w '%{http_code} %{size_download} %{time_total}\n' \ -H "x-bb-connect-machine: <machine credential>" \ "https://<label>.vibecodethis.site/api/v1/big?mb=400"
-
Watch the server's tunnel and the Durable Object outcome. Use GraphQL
durableObjectsInvocationsAdaptiveGroups, or a tail on staging only. Never tail production; see AGENTS.md.
Expected vs actual
Expected: the download completes at the reader's pace, and gate memory stays bounded.
Actual (staging):
200 11501289 43.653391 # curl: cut after 11.5 MB of 400 MB
outcome: exceededMemory # TunnelDO invocation for /api/v1/big?mb=400
exception: Durable Object's isolate exceeded its memory limit
tunnel closed (code 1006); reconnecting in 1000ms # server's own tunnel drops
Evidence
Gate: every body-chunk frame is copied and appended to a promise chain of writer.write() calls. Nothing limits how much is queued while the visitor isn't reading. See apps/connect/src/tunnel-do.ts#L541-L549 and the response TransformStream at #L511.
Client: the tunnel client reads the origin response as fast as the origin produces it and sends every frame immediately. It never checks the WebSocket's bufferedAmount, and the gate can't ask it to pause. See packages/tunnel-client/src/session.ts#L314-L318.
Production (bb-connect, Cloudflare GraphQL durableObjectsInvocationsAdaptiveGroups, status: exceededMemory):
- 2026-09-20: 87 events, all on one server's object.
- 2026-09-24: 2 events on two different objects.
- No minute had more than one object crash, so there's no sign that neighbors in the same isolate are affected.
Large responses that complete successfully today and must keep working (Cloudflare GraphQL httpRequestsAdaptiveGroups, status 200, ranked by bytes):
/internal/server-move/*archives of about 285–310 MB (several a day on Sep 23 and 24).- 127 MB APK downloads.
- Video streams averaging 20–225 MB through port shares.
- About 30 MB
/install/bb-app.tgzfrom older servers.
What I ruled out
- A hard cap on unread bytes per stream / per isolate (tried in Ride bb connect through tunnel resets instead of failing visitors #4313, then removed):
- Staging showed it prevents the crash.
- But it cuts any download whose backlog peaks between 64 MB and the crash point (about 120 MB), and those succeed today.
- A review also found that
writer.abort()doesn't release a write already waiting for a reader that has stopped, so a cap alone doesn't free memory for a stalled visitor.
- Not a duplicate: Evaluate safe retries for retryable Connect Durable Object dispatch failures #2065 covers retrying Durable Object dispatch failures, not buffering.
- Not neighbor crashes: production shows no cross-object crashes, so this only affects the server doing the download.
Proposal
Add stream flow control to the tunnel protocol, gated by PROTOCOL_VERSION. Old clients keep today's behavior.
- The gate tracks unread bytes per HTTP stream: bytes queued minus bytes consumed by the visitor. When they pass a high watermark (e.g. 8 MB), it sends a
stream-pause { streamId }frame. Once they fall below a low watermark (e.g. 2 MB), it sendsstream-resume { streamId }. - The tunnel client pauses the origin
IncomingMessage(res.pause()/res.resume()) for that stream. It also stops reading while the tunnel'sbufferedAmountis high, so a slow uplink doesn't queue frames ahead of heartbeats. - Apply the same to
ws-datafor visitor WebSockets and to request bodies (uploads) in the other direction. - Optionally, for protocol-v1 clients only, keep a generous safety cap well above normal backlogs, so a stalled reader can't crash the object. If a cap is kept, errors the response through its
TransformStreamcontroller so the stuck write is released.
Acceptance: a 400 MB download read at 256 KB/s through staging completes, the Durable Object reports no exceededMemory, and the unread backlog stays near the watermark. Server-move archives, APKs and video streams still work. Tests cover pause/resume ordering and a client that ignores the frames (v1).
Suggested priority and effort
Medium priority, medium effort. It affects servers that serve big files to slow readers, and it drops that server's tunnel when it happens. The workaround is to download on a faster connection. Nothing is lost beyond the failed download and a reconnect.
Found while investigating connect disconnects in bb thread thr_j2j7gu9n5f; related PR #4313.
AGENT GENERATED
Activity
Drop the unread-response cap and address review findings
bb-slop-cop commentedon Sep 26, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotClassification: Bug · High priority · High effort. Labels:
perf,remote,connect,partial-repro.Reproduction and root-cause report: PARTIALLY REPRODUCED, with high confidence in the root cause. The focused test failed in two clean
origin/maincheckouts: the gate accepted 32 MiB before the visitor read it and sent no flow-control signal. The cloud memory reset was not repeated. Reproduction label:partial-repro.Root cause: the gate copies response chunks into a stalled write chain while the tunnel client keeps reading the origin without gate-capacity feedback.
No pull request: a safe fix changes the public tunnel protocol across the gate and client, beyond this rule’s simple-fix limits.