fix(fe/chunk_uploader): improve robustness of chunk uploader
This commit is contained in:
parent
aa56b935a2
commit
33ca87cf2c
2 changed files with 11 additions and 18 deletions
|
@ -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,22 +130,12 @@ export class ChunkUploader {
|
|||
}
|
||||
|
||||
try {
|
||||
let uploadResp: Response<UploadStatusResp> = undefined;
|
||||
for (let i = 0; i < uploadRetryLimit; i++) {
|
||||
uploadResp = await this.client.uploadChunk(
|
||||
const uploadResp = await this.client.uploadChunk(
|
||||
filePath,
|
||||
result.chunk,
|
||||
uploaded
|
||||
);
|
||||
|
||||
if (uploadResp.status === 200) {
|
||||
break;
|
||||
} else if (uploadResp.status !== 429) {
|
||||
break;
|
||||
}
|
||||
await this.backOff();
|
||||
}
|
||||
|
||||
if (uploadResp.status === 200 && uploadResp.data != null) {
|
||||
this.chunkLen = Math.ceil(this.chunkLen * speedUpRatio);
|
||||
return {
|
||||
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue