-
Notifications
You must be signed in to change notification settings - Fork 202
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
Conversation
const partNumber: number = parts.length > 0 ? parts[parts.length - 1].PartNumber! : 0 | ||
const nextPartNumber = partNumber + 1 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense!
@Murderlon Would be possible to publish this fix? |
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" asNextPartNumberMarker
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 useIsTruncated
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.