fix: a short R2 failure no longer fails a customer's upload (DTF-API-D, DTF-WEB-27)
R2 answered ListParts with a 500 twice, 10 s apart, while closing an upload. The storage calls an upload waits on (list parts, complete, head) try again on a 5xx three more times over about 6 s; a 4xx and a timeout go back at once. A complete R2 had in fact done answers NoSuchUpload on the retry: the object is there, so it counts as done. The browser asks to close the upload again after 3 s and 6 s on a server failure; only the last one is reported. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -107,7 +107,22 @@ async function sendUpload(file, {api, prefix='/uploads', startPath=prefix, progr
|
||||
done.add(part);sent+=length(part);
|
||||
onBytes(sent);
|
||||
}
|
||||
await api(prefix+'/'+id+'/complete',{});
|
||||
// Closing the upload reads the parts back from storage, which can fail for
|
||||
// a few seconds (an R2 500, Sentry DTF-API-D, 01/12). Asked again after 3 s
|
||||
// and 6 s, quietly: closing twice is safe, the server answers an upload that
|
||||
// is already closed. A refusal (4xx) is shown at once; only the last
|
||||
// failure reaches the customer and Sentry. No status is a reply that was
|
||||
// not JSON (the gateway's 500 page) or no reply at all.
|
||||
const SERVER_ERRORS=[500,502,503,504];
|
||||
for(let attempt=0;;attempt++){
|
||||
const last=attempt>=2;
|
||||
try{await api(prefix+'/'+id+'/complete',{},last?{}:{expected:SERVER_ERRORS});break;}
|
||||
catch(error){
|
||||
if(last||error?.name==='AbortError'||(error?.status!==undefined&&!SERVER_ERRORS.includes(error.status)))throw error;
|
||||
await new Promise(resolve=>setTimeout(resolve,(attempt+1)*3000));
|
||||
if(signal?.aborted){giveBack();throw cancelled();}
|
||||
}
|
||||
}
|
||||
return waitForScan();
|
||||
}
|
||||
window.dtfUpload = async (file, options) => {
|
||||
|
||||
Reference in New Issue
Block a user