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 upload retry using an outdated ID #4544

Merged
merged 2 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions e2e/cypress/integration/dashboard-aws-multipart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Dashboard with @uppy/aws-s3-multipart', () => {

cy.intercept('POST', '/s3/multipart', { statusCode: 200, times: 1, body: JSON.stringify({ key:'mocked-key-attempt1', uploadId:'mocked-uploadId-attempt1' }) }).as('createMultipartUpload-attempt1')
cy.intercept('GET', '/s3/multipart/mocked-uploadId-attempt1/1?key=mocked-key-attempt1', { forceNetworkError: true }).as('signPart-fails')
cy.intercept('DELETE', '/s3/multipart/mocked-uploadId-attempt1?key=mocked-key-attempt1', { statusCode: 204 }).as('abortAttempt-1')
cy.intercept('DELETE', '/s3/multipart/mocked-uploadId-attempt1?key=mocked-key-attempt1', { statusCode: 200, body: '{}' }).as('abortAttempt-1')
cy.get('.uppy-StatusBar-actions > .uppy-c-btn').click()
cy.wait(['@createMultipartUpload-attempt1', '@signPart-fails', '@abortAttempt-1'])
cy.get('.uppy-StatusBar-statusPrimary').should('contain', 'Upload failed')
Expand All @@ -47,7 +47,7 @@ describe('Dashboard with @uppy/aws-s3-multipart', () => {
},
body: JSON.stringify({ url:'/put-fail', expires:8 }),
}).as('signPart-toFail')
cy.intercept('DELETE', '/s3/multipart/mocked-uploadId-attempt2?key=mocked-key-attempt2', { statusCode: 204 }).as('abortAttempt-2')
cy.intercept('DELETE', '/s3/multipart/mocked-uploadId-attempt2?key=mocked-key-attempt2', { statusCode: 200, body: '{}' }).as('abortAttempt-2')
cy.intercept('PUT', '/put-fail', { forceNetworkError: true }).as('put-fails')
cy.get('.uppy-StatusBar-actions > .uppy-c-btn').click()
cy.wait(['@createMultipartUpload-attempt2', '@signPart-toFail', ...Array(5).fill('@put-fails'), '@abortAttempt-2'], { timeout: 10_000 })
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/aws-s3-multipart/src/MultipartUploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ class MultipartUploader {
this.#onError = this.options.onError
this.#shouldUseMultipart = this.options.shouldUseMultipart

// When we are restoring an upload, we already have an uploadId. Otherwise
// we need to call `createMultipartUpload` to get an `uploadId`.
// When we are restoring an upload, we already have an UploadId and a Key. Otherwise
// we need to call `createMultipartUpload` to get an `uploadId` and a `key`.
// Non-multipart uploads are not restorable.
this.#isRestoring = 'uploadId' in options
this.#isRestoring = options.uploadFile && options.key
aduh95 marked this conversation as resolved.
Show resolved Hide resolved

this.#initChunks()
}
Expand Down
3 changes: 2 additions & 1 deletion packages/@uppy/aws-s3-multipart/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class HTTPCommunicationQueue {
// Remove the cache entry right away for follow-up requests do not try to
// use the soon-to-be aborted chached values.
this.#cache.delete(file.data)
this.#setS3MultipartState(file, Object.create(null))
let awaitedResult
try {
awaitedResult = await result
Expand Down Expand Up @@ -258,7 +259,7 @@ class HTTPCommunicationQueue {
return await this.#sendCompletionRequest(file, { key, uploadId, parts, signal }).abortOn(signal)
} catch (err) {
if (err?.cause !== pausingUploadReason && err?.name !== 'AbortError') {
this.abortFileUpload(file).catch(() => {})
this.abortFileUpload(file).catch(console.warn)
}
throw err
}
Expand Down