fix(upload): stop browser connection exhaustion that froze folder uploads

With WASM finally enabled, large files (e.g. 32 MB logs) started running the
delta worker, which opens SEVERAL concurrent requests each (overlapping
negotiate batches + chunk PUTs). A few of those running at once blew past the
browser's ~6 connections-per-host limit, so plain uploads of the small files
queued with zero bytes sent until the 30 s stall watchdog cancelled them — the
upload "stuck at 4% / 94%" with N (pending) XHRs in the Network panel. The
session-refresh request got starved too (the spurious 401s).

- Raise the delta-worker threshold to 64 MB (new DELTA_WORKER_MIN_SIZE) so
  typical large files take a single-connection plain upload. Delta's payoff is
  sub-file dedup on RE-upload; on a first upload it is pure connection overhead.
  Client-side instant-hashing still only reads files < 8 MB into memory.
- Lower upload concurrency 3 -> 2, leaving headroom under the 6-connection
  budget for session refresh/poll and the occasional delta worker.

npm run check: clean, 58 tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
DioCrafts
2026-06-21 02:33:16 +02:00
parent 9534dfa103
commit 13b59aabd8
2 changed files with 21 additions and 7 deletions
@@ -289,11 +289,12 @@
}
}
// Upload at most this many files concurrently. Bounded so one stuck file
// blocks only its own lane (the others keep going) without overwhelming the
// browser's per-host connection cap, spawning too many delta workers, or
// over-contending the server with many large concurrent uploads.
const UPLOAD_CONCURRENCY = 3;
// Upload at most this many files concurrently. Kept low so we stay well under
// the browser's ~6 connections-per-host budget — leaving headroom for the
// session-refresh/poll requests and (for genuinely huge files) a delta worker,
// which itself opens several connections. Over-subscribing here is what made
// small uploads queue until the watchdog cancelled them ("stuck at N%").
const UPLOAD_CONCURRENCY = 2;
/** Outer backstop deadline (ms). The plain-upload path already self-aborts on
* a stalled connection (see `uploadFileWithProgress`); this only catches a