fix: unblock stalled and frozen uploads
A TUS PATCH rejected before its body was read left the client still streaming a chunk. net/http gives up draining an unread request body after 256KiB and then closes the connection, so the status we replied with was lost and the browser saw a bare transport error instead. The client could not tell a conflict from a network fault, retried blindly, and the upload stalled after the first chunk — while curl, which reads the response as it writes, still reported the status and appeared to work. Drain what is left of a rejected chunk so the answer arrives on a connection that stays usable. The explicit r.Body.Close() had to go with it: it ran before the drain, and the server closes the request body itself once the handler returns. Pressing Upload awaited a recursive listing of the whole destination subtree before a single byte was sent, with no sign that anything was happening. On a large destination that reads as a dead button, and the walk kept running after the client gave up, then reported the failed write as a 500. A flat upload can only collide with a direct child of the destination, so walk recursively only for folder uploads, stop the walk once the request is done, and show the action as busy while the destination is checked. Along the way: a failed upload was credited as fully sent, so the progress bar reported 100% when nothing had been written; the progress timer was recreated without clearing the previous one; and the chunk size field threw on a value with no unit and raced its own debounce on submit, so it appeared to refuse every change. Fixes #6006 Refs #5987
This commit is contained in:
12 files changed
+715
-156
No files matched your search
@@ -103,15 +103,21 @@ export const useUploadStore = defineStore("upload", () => {
|
||||
}
|
||||
|
||||
if (isActiveUploadsOnLimit() && hasPendingUploads()) {
|
||||
if (!hasActiveUploads()) {
|
||||
// Update the state in a fixed time interval
|
||||
if (progressInterval === null) {
|
||||
// Update the state in a fixed time interval. Guard on the handle, not
|
||||
// on the active count: this runs again every time the queue drains to
|
||||
// zero with work still pending, and reassigning would leak the timer.
|
||||
progressInterval = window.setInterval(syncState, 1000);
|
||||
}
|
||||
|
||||
const upload = nextUpload();
|
||||
let succeeded = true;
|
||||
|
||||
if (upload.type === "dir") {
|
||||
await api.post(upload.path).catch($showError);
|
||||
await api.post(upload.path).catch((err) => {
|
||||
succeeded = false;
|
||||
$showError(err);
|
||||
});
|
||||
} else {
|
||||
const onUpload = (event: ProgressEvent) => {
|
||||
upload.rawProgress.sentBytes = event.loaded;
|
||||
@@ -119,10 +125,13 @@ export const useUploadStore = defineStore("upload", () => {
|
||||
|
||||
await api
|
||||
.post(upload.path, upload.file!, upload.overwrite, onUpload)
|
||||
.catch((err) => err.message !== "Upload aborted" && $showError(err));
|
||||
.catch((err) => {
|
||||
succeeded = false;
|
||||
if (err.message !== "Upload aborted") $showError(err);
|
||||
});
|
||||
}
|
||||
|
||||
finishUpload(upload);
|
||||
finishUpload(upload, succeeded);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -135,9 +144,18 @@ export const useUploadStore = defineStore("upload", () => {
|
||||
return upload;
|
||||
};
|
||||
|
||||
const finishUpload = (upload: Upload) => {
|
||||
sentBytes.value += upload.totalBytes - upload.sentBytes;
|
||||
upload.sentBytes = upload.totalBytes;
|
||||
const finishUpload = (upload: Upload, succeeded: boolean) => {
|
||||
if (succeeded) {
|
||||
sentBytes.value += upload.totalBytes - upload.sentBytes;
|
||||
upload.sentBytes = upload.totalBytes;
|
||||
} else {
|
||||
// Credit only what actually reached the server and drop the rest from the
|
||||
// total. Counting a failed upload as fully sent makes the bar report 100%
|
||||
// while nothing was written, which reads as success.
|
||||
sentBytes.value += upload.rawProgress.sentBytes - upload.sentBytes;
|
||||
totalBytes.value -= upload.totalBytes - upload.rawProgress.sentBytes;
|
||||
upload.sentBytes = upload.rawProgress.sentBytes;
|
||||
}
|
||||
upload.file = null;
|
||||
|
||||
activeUploads.value.delete(upload);
|
||||
|
||||
Reference in new issue
Block a user