Repository navigation
fix(cloud): address workspaces a few at a time so one batch cannot exhaust file descriptors - #10170
Merged
Merged
Conversation
Contributor
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
No installed development build can load this pull request as an update: its native fingerprint is |
Contributor
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
…haust file descriptors The desktop keeps a live address for every live cloud workspace in the organization, and tRPC batches those `access` calls into one request (64+ in production). Each call makes several outbound fetches (Neon HTTP per query, PostHog flags, the Vercel Sandbox API, realtime/QStash), and the batch ran them all at once. undici does not cap connections per origin, so a single request ran the function instance out of file descriptors: every fetch then failed (NeonDbError: fetch failed) and Sentry's own process.memoryUsage() threw EMFILE. A wake batched into the same request failed with it, which is the "Waking up workspace" banner on awake boxes. Address-only `access` calls now run at most 8 at a time per instance. A wake is not held behind them. Fixes API-4J Fixes API-4N Fixes API-4E Fixes API-4F Fixes API-4Q Fixes API-4R
… not read SANDBOX_GATE_ORIGIN
saddlepaddle
force-pushed
the
saddlepaddle/fix-cloud-access-emfile
branch
from
November 23, 2026 00:17
3a318c5 to
c3672b9
Compare
saddlepaddle
marked this pull request as ready for review
November 23, 2026 00:23
This branch was previously deployed
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.
Root cause
cloudWorkspace.accessfails in production because a single batched request exhausts the function instance's file descriptors.SandboxAccessProviderkeeps a live address (access,wake: false) for every live cloud workspace in the organization. Cloud workspaces are org-wide, so a large org means many calls.httpBatchLinksends them as one HTTP request, and tRPC runs every call in that batch concurrently./flags, the Vercel Sandbox API (describeSandbox), and realtime/QStash on a transition. undici does not cap connections per origin, so N concurrent calls open about N sockets on each origin.NeonDbError: Error connecting to database: TypeError: fetch failed). Sentry's ownprocess.memoryUsage()call (uv_resident_set_memoryopens/proc/self/stat) then throws EMFILE, unhandled. If the open workspace'swakeis in the same batch, it fails too, and the desktop shows "Waking up workspace / Retry" on a box that is awake.Verified (Sentry)
fetch failedevent in projectapiis on this one transaction. That is 5,759 events in 208 traces, about 28 per request. No other transaction on the same instances fails, so the instance does not leak over time. One request exhausts it.cloud_workspace.ids fail. Errors arrive 20 to 64 at a time within the same second, which is one batch failing together.Inferred, not verified
asleepworkspaces too, and feat(cloud): backfill legacy cloud workspace statuses (ready by a full Vercel listing, deleted by migration) #9802 backfilled legacy rows to live statuses. I did not count production rows.@vercel/sandbox4.0.0 shares one module-level undiciAgent, and the DB clients are module singletons.nudgeandhostServiceAnswersdon't read their response bodies, which holds a socket until GC, but they are off the hot path and outside this fix's scope.Fix
Address-only
accesscalls run at most 8 at a time per instance (createConcurrencyLimit). A wake is not throttled, so the open workspace is never queued behind the sidebar. Released desktop and mobile builds benefit without an update. The API contract does not change.The trade-off: a batch of 64 addresses now takes about 8 rounds instead of 1. Addresses are background work, so this costs some seconds once, not a visible stall. A wake that shares the batch still waits for the batch response (
httpBatchLinkis not streaming), but it now succeeds instead of failing.Test
cloud-workspace.test.ts› "cloudWorkspace.access in one large batch": sends 64 concurrent address calls with the provider read held, then sends a wake.Expected: <= 8, Received: 64.Checks
bun testin packages/trpc: 1199 pass, 0 failbun run typecheckin packages/trpc: cleanbiome check packages/trpc/src/router/cloud-workspace/: cleanNot yet verified in production: whether EMFILE stops after deploy. Watch API-4J/4N on the release that carries this.
Fixes API-4J, API-4N, API-4E, API-4F, API-4Q, API-4R
How to undo
8increateConcurrencyLimit(8)inpackages/trpc/src/router/cloud-workspace/cloud-workspace.ts.concurrency-limit.tsand thelimitAddresswrapper inaccessonce clients stop addressing every workspace in the list (address only the open one), or once the API has a global cap on outbound connections.Summary by cubic
Fixes production EMFILE /
fetch failederrors where one batchedcloudWorkspace.accessrequest exhausted the instance's file descriptors. The desktop addresses every live cloud workspace in one tRPC batch, and each address opens several sockets per origin, so a large org runs past the descriptor limit and every fetch in the batch fails — including wakes.Address-only
accesscalls now run at most 8 at a time per instance viacreateConcurrencyLimit. A wake is not throttled, so the open workspace is never queued behind the sidebar. The trade-off is that a batch of 64 addresses takes about 8 rounds instead of 1, but addresses are background work, so it costs a few seconds once rather than a visible stall.Written for commit c3672b9. Summary will update on new commits.