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: Fix race condition in #uploadParts #3955

Merged
merged 2 commits into from Aug 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/@uppy/aws-s3-multipart/src/MultipartUploader.js
Expand Up @@ -278,26 +278,25 @@ class MultipartUploader {
#uploadPartRetryable (index, prePreparedPart) {
return this.#retryable({
before: () => {
this.chunkState[index].busy = true
this.partsInProgress += 1
},
attempt: () => this.#uploadPart(index, prePreparedPart),
after: () => {
this.chunkState[index].busy = false
this.partsInProgress -= 1
},
})
}

#uploadPart (index, prePreparedPart) {
this.chunkState[index].busy = true

const valid = typeof prePreparedPart?.url === 'string'
if (!valid) {
throw new TypeError('AwsS3/Multipart: Got incorrect result for `prePreparedPart`, expected an object `{ url }`.')
}

const { url, headers } = prePreparedPart
if (this.#aborted()) {
this.chunkState[index].busy = false
throw createAbortError()
}

Expand Down Expand Up @@ -359,14 +358,12 @@ class MultipartUploader {

xhr.addEventListener('abort', () => {
cleanup()
this.chunkState[index].busy = false

defer.reject(createAbortError())
})

xhr.addEventListener('load', (ev) => {
cleanup()
this.chunkState[index].busy = false

if (ev.target.status < 200 || ev.target.status >= 300) {
const error = new Error('Non 2xx')
Expand Down Expand Up @@ -394,7 +391,6 @@ class MultipartUploader {

xhr.addEventListener('error', (ev) => {
cleanup()
this.chunkState[index].busy = false

const error = new Error('Unknown error')
error.source = ev.target
Expand Down