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

@tus/s3-store: Fix incorrect part retreival procedure #507

Merged
merged 2 commits into from
Nov 1, 2023

Conversation

mitjap
Copy link
Collaborator

@mitjap mitjap commented Oct 26, 2023

This PR fixes some issues with retrieveParts function.

First issue is how it determines when to fetch more parts. Before it was using data.NextPartNumberMarker && Number(data.NextPartNumberMarker) > 0 to check if there are more parts to be fetch. This code made an assumption that final "page" will return "0" as NextPartNumberMarker but this is not specified in documentation and differs between S3 providers. Scaleway's S3 for example always return last part's number. Specification is clear on this that we should use IsTruncated propery.

Next issue is with sorting the parts. When completing multipart upload parts must be ordered in ascending order. In existing code sorting was done only when there less then 1000 parts (no additional "pages").

Another issue is with filtering. I'm not sure why would we ever need to remove parts from this list.

@mitjap mitjap marked this pull request as draft October 26, 2023 19:09
@mitjap mitjap marked this pull request as ready for review October 26, 2023 19:23
Comment on lines +482 to 483
const partNumber: number = parts.length > 0 ? parts[parts.length - 1].PartNumber! : 0
const nextPartNumber = partNumber + 1
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nextPartNumber should be calculated from last part number

parts
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
.sort((a, b) => a.PartNumber! - b.PartNumber!)
.filter((value, index) => value.PartNumber === index + 1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this filter was kind of fail-safe if some part in the middle was not uploaded. This does not prevent later file corruption if some part was uploaded only partially.

Copy link
Member

@Murderlon Murderlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@Murderlon Murderlon merged commit 7ae0bf7 into tus:main Nov 1, 2023
2 checks passed
@mitjap mitjap deleted the s3-improve-list-parts branch November 6, 2023 09:20
@mitjap
Copy link
Collaborator Author

mitjap commented Nov 6, 2023

@Murderlon Would be possible to publish this fix?

@Murderlon
Copy link
Member

Done!
https://github.com/tus/tus-node-server/releases/tag/%40tus%2Fs3-store%401.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants