Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/aws-s3-multipart: handle slow connections better #4213

Merged
merged 2 commits into from
Nov 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/@uppy/aws-s3-multipart/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class HTTPCommunicationQueue {

#listParts

#previousRetryDelay

#requests

#retryDelayIterator
Expand Down Expand Up @@ -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
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
}
// 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.
Expand Down