Skip to content

fix(upload): send Storage uploads with fetch in the standalone binary - #359

Merged
riglar merged 1 commit into
devfrom
fix/2263-bun-tus-upload
Nov 24, 2026
Merged

riglar merged 1 commit into
devfrom
fix/2263-bun-tus-upload

Conversation

@riglar

@riglar riglar commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Problem

The standalone dcd binary (built with bun build --compile) could not upload to Supabase Storage. tus-js-client's default Node HTTP stack pipes each chunk into a node:http request. Under Bun, the first request (the POST that creates the upload, sent with the first 6 MB chunk) fails with:

tus: failed to create upload, caused by Error: The socket connection was closed unexpectedly

The B2 upload still succeeded, so the command exited 0. The binary was stored without its Storage copy, and only --debug showed the error. The npm package, which runs on Node, was not affected.

Fix

  • New src/gateways/fetch-http-stack.ts: a small tus HttpStack that reads each chunk into memory and sends it with fetch. tus sends one chunk per request, so this holds at most one 6 MB chunk at a time. fetch can't report upload progress, so progress moves once per chunk.
  • SupabaseGateway.uploadResumable uses it only under Bun. Under Node, tus keeps its default stack, unchanged.
  • tusHttpStackOptions() returns {} under Node, not { httpStack: undefined }. tus spreads options over its defaults, so an explicit undefined would remove the default stack.

Testing

  • Minimal repro script (tus-js-client, 7 MB file, real Supabase Storage): fails under Bun with the default stack, passes under Bun and Node with the fetch stack. A 20 MB, multi-chunk upload also passes.
  • Compiled the binary with bun build --compile and ran dcd upload --debug against the dev API: Backblaze: ✓, Supabase: ✓, and the stored binary has its Storage path.
  • New unit tests: a full chunked upload through FetchHttpStack against a local tus server (data on create, then PATCHes), error handling, and the Bun/Node option choice.
  • pnpm lint, pnpm typecheck, pnpm test:unit (769 passing).

Tested on darwin-arm64 only. Linux and Windows binaries use the same code path.

🤖 Generated with Claude Code

The standalone binary runs on Bun. tus-js-client's default Node HTTP stack
pipes each chunk into a node:http request, and under Bun the upload-creating
POST fails with "The socket connection was closed unexpectedly". So every
binary uploaded from the standalone CLI was stored without its Storage copy.
The B2 upload still succeeded, so the command exited 0 and only --debug
showed the error.

Under Bun, tus now uses a small fetch-based HTTP stack that reads each chunk
into memory (one chunk, 6 MB, at a time) and sends it with fetch. Node keeps
tus's default stack unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@claude

claude Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@riglar
riglar merged commit e03a78e into dev Nov 24, 2026
9 checks passed
@riglar
riglar deleted the fix/2263-bun-tus-upload branch November 24, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant