fix(sandbox): make the daemon URL-transfer routes async - #5413
Merged
Conversation
write_from_url and upload_to_url ran fs.mkdirSync/rmSync/statSync directly in the request handler, blocking the daemon's single-threaded event loop on every call (mkdirSync/statSync on every request, rmSync on failure). This mirrors the read/rename route fixes (#5403, #5406) using the already-imported mkdir/rm/stat promises.
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.
Follows #5403/#5406, which converted the daemon's read and rename routes off blocking sync fs calls.
write_from_urlandupload_to_urlinpackages/sandbox/daemon/routes/fs.tsstill calledfs.mkdirSync/fs.rmSync/fs.statSyncdirectly in the request handler.Per CONTRIBUTING.md rule #1, the sandbox daemon runs on a single-threaded Bun event loop — any sync fs call blocks it from answering its HTTP health probe, and Studio tears down / recovers a sandbox on a single missed probe.
mkdirSync/statSyncran on every call to these routes, andrmSyncran on every failed transfer.The fix swaps each sync call for its already-imported
node:fs/promisesequivalent (mkdir/rm/statwere already imported and used elsewhere in the file) — a straight 1:1 behavior-preserving substitution, same as the prior read/rename PRs. Renamed the localstatvariable tofileStatto avoid shadowing the importedstatfunction.To verify:
cd packages/sandbox && bunx tsc --noEmit, thenbun test packages/sandbox/daemon/routes/fs.test.ts(56 pass, 0 fail — existing coverage of this file passes unchanged since behavior is identical).Locally ran:
bun run fmt,bunx tsc --noEmit(packages/sandbox workspace), and the targeted test file above. Full CI validates the rest.Summary by cubic
Make the sandbox daemon’s URL-transfer routes async to avoid blocking the single-threaded event loop and prevent health probe timeouts. Replaced sync
fscalls inwrite_from_urlandupload_to_urlwithnode:fs/promisesto keep behavior the same while non-blocking.mkdirSync/rmSync/statSyncformkdir/rm/statinpackages/sandbox/daemon/routes/fs.ts.stattofileStatto avoid shadowing the importedstatfunction.Written for commit 10874d9. Summary will update on new commits.