From 33ca87cf2c5ff8a374c2286c4688785907181cb3 Mon Sep 17 00:00:00 2001 From: hexxa Date: Sun, 9 Jan 2022 21:19:30 +0800 Subject: [PATCH] fix(fe/chunk_uploader): improve robustness of chunk uploader --- src/client/web/src/worker/chunk_uploader.ts | 27 ++++++++------------- src/iolimiter/iolimiter.go | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/client/web/src/worker/chunk_uploader.ts b/src/client/web/src/worker/chunk_uploader.ts index b5256d5..aa637e2 100644 --- a/src/client/web/src/worker/chunk_uploader.ts +++ b/src/client/web/src/worker/chunk_uploader.ts @@ -16,7 +16,7 @@ const chunkLimit = 1024 * 1024 * 50; // 50MB const createRetryLimit = 1024; const uploadRetryLimit = 1024; const readRetryLimit = 8; -const backoffMax = 2000; +const backoffMax = 5000; export interface ReaderResult { chunk?: string; @@ -56,9 +56,9 @@ export class ChunkUploader { }; } } catch (e) { - await this.backOff(); console.error(e); } + await this.backOff(); } return { @@ -130,21 +130,11 @@ export class ChunkUploader { } try { - let uploadResp: Response = undefined; - for (let i = 0; i < uploadRetryLimit; i++) { - uploadResp = await this.client.uploadChunk( - filePath, - result.chunk, - uploaded - ); - - if (uploadResp.status === 200) { - break; - } else if (uploadResp.status !== 429) { - break; - } - await this.backOff(); - } + const uploadResp = await this.client.uploadChunk( + filePath, + result.chunk, + uploaded + ); if (uploadResp.status === 200 && uploadResp.data != null) { this.chunkLen = Math.ceil(this.chunkLen * speedUpRatio); @@ -194,6 +184,9 @@ export class ChunkUploader { err: `failed to get upload status: ${uploadStatusResp.statusText}`, }; } catch (e) { + this.chunkLen = Math.ceil(this.chunkLen * speedDownRatio); + await this.backOff(); + return { filePath, uploaded: uploaded, diff --git a/src/iolimiter/iolimiter.go b/src/iolimiter/iolimiter.go index 1738d1a..fea2350 100644 --- a/src/iolimiter/iolimiter.go +++ b/src/iolimiter/iolimiter.go @@ -4,8 +4,8 @@ import ( "fmt" "sync" - "github.com/ihexxa/quickshare/src/golimiter" "github.com/ihexxa/quickshare/src/db/userstore" + "github.com/ihexxa/quickshare/src/golimiter" ) const cacheSizeLimit = 1024