diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts index f383662a1a9c..003e1a5821d0 100644 --- a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.ts @@ -73,9 +73,10 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy token: this.authService.getAccessToken(), uploaderClass: UploaderXFormData, retryConfig: { - maxAttempts: 6, - shouldRetry: (code: number) => { - return code < 400 || code >= 501 + maxAttempts: 30, // maximum attempts for 503 codes, otherwise set to 6, see below + maxDelay: 120_000, // 2 min + shouldRetry: (code: number, attempts: number) => { + return code === HttpStatusCode.SERVICE_UNAVAILABLE_503 || ((code < 400 || code > 500) && attempts < 6) } } } diff --git a/server/lib/redis.ts b/server/lib/redis.ts index a3a8727922b5..69a9327db347 100644 --- a/server/lib/redis.ts +++ b/server/lib/redis.ts @@ -207,7 +207,7 @@ class Redis { setUploadSession (uploadId: string, video?: { id: number, uuid: string }) { return this.setObject( - uploadId, + 'resumable-upload-' + uploadId, video ? { id: video.id.toString(), @@ -219,11 +219,11 @@ class Redis { } doesUploadSessionExist (uploadId: string) { - return this.exists(uploadId) + return this.exists('resumable-upload-' + uploadId) } getUploadSession (uploadId: string) { - return this.getValue(uploadId) + return this.getValue('resumable-upload-' + uploadId) } /* ************ Keys generation ************ */ diff --git a/server/middlewares/validators/videos/videos.ts b/server/middlewares/validators/videos/videos.ts index 7d440e2101b8..74d01d3f902c 100644 --- a/server/middlewares/validators/videos/videos.ts +++ b/server/middlewares/validators/videos/videos.ts @@ -121,7 +121,7 @@ const videosAddResumableValidator = [ if (!sessionResponse) { res.setHeader('Retry-After', 300) // ask to retry after 5 min, knowing the upload_id is kept for up to 15 min after completion res.fail({ - status: HttpStatusCode.CONFLICT_409, + status: HttpStatusCode.SERVICE_UNAVAILABLE_503, message: 'The upload is already being processed' }) } else { diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml index f43943ec139f..36555e0cd02f 100644 --- a/support/doc/api/openapi.yaml +++ b/support/doc/api/openapi.yaml @@ -2039,11 +2039,18 @@ paths: '404': description: upload not found '409': - description: chunk doesn't match range or upload being processed + description: chunk doesn't match range '422': description: video unreadable '429': description: too many concurrent requests + '503': + description: upload is already being processed + headers: + 'Retry-After': + schema: + type: number + example: 300 delete: summary: Cancel the resumable upload of a video, deleting any data uploaded so far description: Uses [a resumable protocol](https://github.com/kukhariev/node-uploadx/blob/master/proto.md) to cancel the upload of a video