From 2c7111068cb50cdaff5c08b77e81f6bc1f1d65fa Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sun, 13 Nov 2022 00:26:46 +0100 Subject: [PATCH 1/2] @uppy/aws-s3-multipart: handle slow connections better --- packages/@uppy/aws-s3-multipart/src/index.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/@uppy/aws-s3-multipart/src/index.js b/packages/@uppy/aws-s3-multipart/src/index.js index 7f4932a60c..33846acfa6 100644 --- a/packages/@uppy/aws-s3-multipart/src/index.js +++ b/packages/@uppy/aws-s3-multipart/src/index.js @@ -33,6 +33,8 @@ class HTTPCommunicationQueue { #listParts + #previousRetryDelay + #requests #retryDelayIterator @@ -86,13 +88,19 @@ class HTTPCommunicationQueue { } if (status === 403 && err.message === 'Request has expired') { if (!requests.isPaused) { - const next = this.#retryDelayIterator?.next() - if (next == null || next.done) { - return false + // We don't want to exhaust the retryDelayIterator as long as there are + // more than one request in parallel, to give slower connection a chance + // to catch up with the expiry set in Companion. + if (requests.limit === 1 || this.#previousRetryDelay == null) { + const next = this.#retryDelayIterator?.next() + if (next == null || next.done) { + return false + } + this.#previousRetryDelay = next.value } // No need to stop the other requests, we just want to lower the limit. requests.rateLimit(0) - await new Promise(resolve => setTimeout(resolve, next.value)) + await new Promise(resolve => setTimeout(resolve, this.#previousRetryDelay)) } } else if (status === 429) { // HTTP 429 Too Many Requests => to avoid the whole download to fail, pause all requests. From de888745d1b91324b5bb1450230cbbbdf456833c Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 16 Nov 2022 14:35:30 +0100 Subject: [PATCH 2/2] Update packages/@uppy/aws-s3-multipart/src/index.js --- packages/@uppy/aws-s3-multipart/src/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/@uppy/aws-s3-multipart/src/index.js b/packages/@uppy/aws-s3-multipart/src/index.js index 33846acfa6..06f1e87169 100644 --- a/packages/@uppy/aws-s3-multipart/src/index.js +++ b/packages/@uppy/aws-s3-multipart/src/index.js @@ -96,6 +96,12 @@ class HTTPCommunicationQueue { if (next == null || next.done) { return false } + // If there are more than 1 request done in parallel, the RLQ limit is + // decreased and the failed request is requeued after waiting for a bit. + // If there is only one request in parallel, the limit can't be + // decreased, so we iterate over `retryDelayIterator` as we do for + // other failures. + // `#previousRetryDelay` caches the value so we can re-use it next time. this.#previousRetryDelay = next.value } // No need to stop the other requests, we just want to lower the limit.