Repository navigation
Restart a tunnel Durable Object whose tunnel socket vanished - #4268
Merged
Merged
Conversation
A restart of the gate's Durable Objects (any bb-connect deployment, and now recurring platform-side events) can orphan hibernated tunnel sockets: the bb keeps an open socket nobody answers, visitors get 503, and a busy object never heals. TunnelDO now records when it accepts a tunnel and when the last tunnel socket closes. A visitor request, a tunnel dial, or the presence alarm that finds no live socket although the last one never closed durably records a close (storage.sync before abort, or the record is lost and the object loops) and calls ctx.abort(), so the bb redials into a fresh object. Objects from older code that still list a server or machine restart once the same way. Split out of #4251 so it can ship ahead of the account stack. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
SawyerHood
added a commit
that referenced
this pull request
Sep 24, 2026
…with a canary The gate half of #4227, plus the rollout tooling the 2026-09-24 outage called for. The tunnel self-restart that fixed the outage itself landed separately in #4268. - The gate accepts a `bbtkt_` tunnel ticket in place of the raw credential when TUNNEL_TICKETS is "on". Production ships "off"; a refused ticket gets 401, which bb answers by dialing with its raw credential. Staging and local cloud dev run "on". - Roll out Connect gate (workflow_dispatch) connects a canary, deploys an uploaded version at 0%, 5%, 25% or 100% with `wrangler versions deploy`, and requires the canary's tunnel to be back within 120 s and then hold. It rolls back with `wrangler rollback` if the canary fails, and reads each environment's canary settings without falling back to production's. It refuses to start while another split is deployed. - @bb/connect-rollout holds the canary and the step planner. The canary holds a tunnel as a dedicated server, answers its own hostname through that tunnel, and with --recover-within redials after a drop and fails unless it is back in time. - Deploy Connect's summary points at the workflow. - docs/connect-gate-rollout.md covers why every deployment disconnects tunnels, how Cloudflare assigns versions for a Worker with Durable Objects (entrypoint per request, each object pinned per deployment), the steps, what to watch, and rollback (`wrangler rollback`, never `versions deploy <old>@100%`). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
When the gate's tunnel Durable Objects restart, hibernated tunnel WebSockets can be orphaned. The bb keeps an open socket that nothing answers, so its heartbeats go unanswered. The object has no tunnel socket, so visitors get
503 offline. After 60 s the bb redials, and while the object keeps getting requests, every new dial is orphaned the same way. An object heals only after about 45 s with no requests, which busy servers never get. #4251 reproduced this on staging: any deployment ofbb-connect, even an unchanged version, triggers it (runs X0–X7 there).This caused the 2026-09-24 01:07 outage, and it's happening again in prod without any gate deploy. Prod
bb-connecthas stayed on6f79c289since the 01:43 rollback. Since about 07:00 UTC, Durable Object outcomes show recurring bursts at 08:45–10:30, 12:30, 13:30, 14:30 and 16:15, each withresponseStreamDisconnectedup 5–10× andscriptThrewExceptionup 10–20×. Each burst leaves more servers stuck:*.getbb.appclimbed from 9–10% overnight to 16–30% per hour;tunnel heartbeat missedevery minute again.The current gate has no way to recover.
What changed
This is the
TunnelDOself-restart from #4251, split out so it can ship ahead of the account stack. It contains no ticket code and no workflow changes.apps/connect/src/tunnel-do.ts:tunnelOpenedAtwhen it accepts a tunnel andtunnelClosedAtwhen the last tunnel socket closes or the owner revokes it.storage.sync(), thenctx.abort(). The restarted object drops the orphaned socket and the bb redials into a working object.sync()is required. Without it,abort()discards the write and the object restarts forever (586 aborts in staging run B1 of Accept tunnel tickets behind a flag, and document deploying the gate by hand #4251).serverId/machineId; they restart once the same way, so the first deploy of this code heals existing stuck objects.apps/connect/src/worker.test.ts: aTunnelDO restarts after its tunnel socket vanishessuite. It restarts on a visitor request, a dial and the alarm. It doesn't restart after a recorded close, within the grace period, or with a live socket. Legacy objects restart exactly once, and the close record survives the restart.How you verified
origin/main'stunnel-do.tsthe new suite fails 5 of 9; with this change 9 of 9 pass.pnpm exec turbo run typecheck lint test --filter=@bb/connect: pass (130 tests).tunnel-do.tslogic:internalErrorwent 205 → 0.Rollout
Deploy Connect is enabled, so merging deploys this with
wrangler deployat 100%. That's acceptable: the deploy orphans the tunnels, and this code restarts them. On staging (#4251 B2), all tunnels were back within about 40 s. The gentler path, recommended in #4251, is:pnpm --filter @bb/connect exec wrangler versions upload.pnpm --filter @bb/connect exec wrangler rollback <new-version-id> -m "gate: tunnel self-restart". A rollback to a never-deployed version closed tunnels cleanly on staging (Accept tunnel tickets behind a flag, and document deploying the gate by hand #4251 X11).Either way, go straight to 100%: objects still on old code can't restart.
For 30 minutes afterwards, watch:
*.getbb.app;internalError(one spike as stuck objects restart, then 0) andclientDisconnected;grep 'plugin:connect\] tunnel' ~/.bb/logs/server-stdio.logon bee.Rollback
pnpm --filter @bb/connect exec wrangler rollback 6f79c289-9e43-4697-b056-78e31bc3e6ad -m "<reason>". Usewrangler rollback, neverversions deploy <old>@100%: rollbacks closed tunnels cleanly every time we saw one, and a deployment orphans them again.🤖 Generated with Claude Code