Skip to content

Commit

Permalink
Enhanced uploading files with tus protocol, enabled retries (#7830)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsekachev authored May 3, 2024
1 parent ce5e07c commit 04f3c84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20240430_172649_boris_enable_tus_retries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

Uploading files with TUS immediately failed when one of the requests failed
(<https://github.com/cvat-ai/cvat/pull/7830>)
2 changes: 1 addition & 1 deletion cvat-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cvat-core",
"version": "15.0.3",
"version": "15.0.4",
"type": "module",
"description": "Part of Computer Vision Tool which presents an interface for client-side integration",
"main": "src/api.ts",
Expand Down
15 changes: 14 additions & 1 deletion cvat-core/src/server-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,20 @@ async function chunkUpload(file: File, uploadConfig): Promise<{ uploadSentSize:
Authorization: Axios.defaults.headers.common.Authorization,
},
chunkSize,
retryDelays: null,
retryDelays: [2000, 4000, 8000, 16000, 32000, 64000],
onShouldRetry(err: tus.DetailedError | Error): boolean {
if (err instanceof tus.DetailedError) {
const { originalResponse } = (err as tus.DetailedError);
const code = (originalResponse?.getStatus() || 0);

// do not retry if (code >= 400 && code < 500) is default tus behaviour
// retry if code === 409 or 423 is default tus behaviour
// additionally handle codes 429 and 0
return !(code >= 400 && code < 500) || [409, 423, 429, 0].includes(code);
}

return false;
},
onError(error) {
reject(error);
},
Expand Down

0 comments on commit 04f3c84

Please sign in to comment.