Repository navigation
fix(upload): stop Bunny uploads from silently restarting from zero - #159
Merged
Merged
Conversation
tus-js-client defaulted to one PATCH for the whole file, and Bunny resumes only from the last chunk it acknowledged, so any dropped connection in a multi-GB upload, even with the bar at 100%, restarted it from zero. All three browser call sites now share BUNNY_TUS_OPTIONS with 50 MiB chunks and Bunny's documented retry delays. The TUS signature, the signed upload grant and the quota hold were 1h, 1h and 2h. Bunny checks AuthorizationExpire on every HEAD and PATCH, so a retry past the hour failed with a 400, and an upload that finished past the hour was refused when saved. Signed-in uploads now get one shared 6h lifetime; guest uploads keep their 1h token and 30 min hold.
After a dropped connection tus-js-client asks Bunny how far the upload got. Any answer but 2xx or 423, a passing 502 included, made it create a new upload and send the whole file again, and Bunny accepts a second upload for the same video, so the bar fell back to 0% with no error. Reproduced against a real Bunny library: HEAD 502, then POST 201 and the upload restarted at 0%. pinToCreatedUpload drops the endpoint once the upload URL exists, so that answer is retried against the same upload instead. The default retry rule also gave up while navigator.onLine was false, so ten seconds offline failed the upload outright. And when the connection dropped after the last byte, the browser could resend the final PATCH after Bunny had already finished, get a 404 and fail an upload that was complete. Both are now retried; the retry's HEAD resumes, or ends the upload as a success.
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.
Large Bunny uploads could reach a high percentage and then start over from 0% with no error, and a short Wi-Fi drop failed them outright.
What was tested. I ran live tests against a Bunny Stream test library using headless Chromium, the shipped tus-js-client 4.3.1 and this PR's
lib/client/bunny-tus.ts. A CONNECT proxy cut the connection, and a Playwright route injected a 502. The test file was a 325 MiB 1080p video.Bunny encoded the chunked, resumed uploads at 1080p. All test videos were deleted afterwards.
Why.
_resumeUploaddrops the URL and POSTs a new upload toendpoint. Bunny accepts a second upload for the same video, even one that is already encoded, so a passing 5xx makes tus quietly send the whole file again. I have not caught Bunny returning such a HEAD in production. The test injected it, so that link is still an assumption.onShouldRetrygives up whenevernavigator.onLineis false.Change (
lib/client/bunny-tus.ts, wired into all three browser call sites):pinToCreatedUploadnulls the endpoint once the upload URL exists. A failed resume HEAD is then retried against the same upload (5xx) or reported (4xx). It never re-sends the file into a new upload.onShouldRetryretries everything except 4xx. 409, 423 and a 404 on PATCH stay retryable, and it keeps retrying while offline. The retry delays still cap attempts at 7 per stall, about 2.5 minutes.AuthorizationExpireon every HEAD and PATCH, so a retry past the hour failed. Guest uploads keep a 1h token and a 30 min hold. An upload abandoned without the client's DELETE now holds its quota for up to 6h instead of 2h. Expired holds are already ignored by the quota sums.Validation.
bun run checkpasses. The newtests/unit/lib/client/bunny-tus.test.tspasses, and so do the token and version hook tests.