Skip to content

Commit

Permalink
aws-s3-multipart: fix stuck upload with limit: 1 (#2475)
Browse files Browse the repository at this point in the history
Fixes #2463

There was an issue with the timing of the `_uploadParts()` call. That
function is responsible for _starting_ the upload of multiple parts of
the file. It can start up to `limit` simultaneous uploads, depending on
how many parts are currently uploading.

`_uploadParts()` was called during the completion code for an individual
part. However, the `partsInProgress` state would not be updated until
_after_ the completion code had run. So, inside `_uploadParts()`, it
would see an outdated `partsInProgress` value. Often, this worked OK (if
not optimally) because there would likely be another part in progress,
and once _that_ finished, there would be space again in the
`partsInProgress` value. However, this was _not_ the case if `limit` was
set to 1. In that case, the first part would finish, then we would enter
`_uploadParts()`, and it would see that we were at the limit: it would
not start a new part upload. After, it would never be called again.

This moves the `_uploadParts()` call to _after_ the part upload
completion code. It is now inside `_uploadParts()`, which I think
generally makes the sequencing a bit more clear. Everything related to a
single part upload now has to be complete before `_uploadParts()` runs
again.
  • Loading branch information
goto-bus-stop authored Aug 31, 2020
1 parent 886f059 commit 9c8ff48
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/@uppy/aws-s3-multipart/src/MultipartUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ class MultipartUploader {
}

candidates.forEach((index) => {
this._uploadPartRetryable(index).catch((err) => {
this._uploadPartRetryable(index).then(() => {
// Continue uploading parts
this._uploadParts()
}, (err) => {
this._onError(err)
})
})
Expand Down Expand Up @@ -281,8 +284,6 @@ class MultipartUploader {
this.parts.push(part)

this.options.onPartComplete(part)

this._uploadParts()
}

_uploadPartBytes (index, url, headers) {
Expand Down

0 comments on commit 9c8ff48

Please sign in to comment.