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

fix: half-written asset zips can be uploaded if process is interrupted #22393

Merged
merged 5 commits into from Oct 6, 2022

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Oct 6, 2022

Here's a possible scenario that can lead to "Uploaded file must be a non-empty zip":

  • Bundling starts
  • A partial zip file is written
  • The process is interrupted (^C or similar) while writing.
  • On next run, the destination file already exists, is taken to be complete, and uploaded.

In this fix, we'll write the zip to a temporary file and atomically rename it into place once finished, thereby avoiding this possible scenario.

Attempts to fix #18459.

I don't have tests for this, I don't know how to write them properly. To my mind, if the code looks good and we pass integration tests, that should be sufficient. Add a global asset salting mechanism so that we know all asset hashes are always unique.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Here's a possible scenario that can lead to "Uploaded file must be a
non-empty zip":

- Bundling starts
- A partial zip file is written
- The process is interrupted (`^C` or similar) while writing.
- On next run, the destination file already exists, is taken to be
  complete, and uploaded.

In this fix, we'll write the zip to a temporary file and atomically
rename it into place once finished, thereby avoiding this possible
scenario.

Attempts to fix #18459.
@rix0rrr rix0rrr requested a review from a team October 6, 2022 14:56
@rix0rrr rix0rrr self-assigned this Oct 6, 2022
@gitpod-io
Copy link

gitpod-io bot commented Oct 6, 2022

@github-actions github-actions bot added bug This issue is a bug. p1 labels Oct 6, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team October 6, 2022 14:56
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Oct 6, 2022
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@rix0rrr rix0rrr added pr-linter/exempt-test The PR linter will not require test changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Oct 6, 2022
}

/**
* Rename the file to the target location, taking into account that we may see EPERM on Windows
Copy link
Contributor

Choose a reason for hiding this comment

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

🙈

@aws-cdk-automation aws-cdk-automation dismissed their stale review October 6, 2022 14:58

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

@jogold
Copy link
Contributor

jogold commented Oct 6, 2022

  • On next run, the destination file already exists, is taken to be complete, and uploaded.

How about checking the file size in the cache against EMPTY_ZIP_FILE_SIZE here? (and rezip even if it exists in this case)

if (await pathExists(packagedPath)) {
this.host.emitMessage(EventType.CACHED, `From cache ${packagedPath}`);
return { packagedPath, contentType };
}

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Oct 6, 2022

How about checking the file size in the cache against EMPTY_ZIP_FILE_SIZE here? (and rezip even if it exists in this case)

That will only catch the case if it's actually empty, not if we succesfully wrote 10MB and yet still failed because were supposed to write 100MB.

@mergify
Copy link
Contributor

mergify bot commented Oct 6, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 5f80c2d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 2ed006e into main Oct 6, 2022
@mergify mergify bot deleted the huijbers/zip-temporarily branch October 6, 2022 17:30
@mergify
Copy link
Contributor

mergify bot commented Oct 6, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

arewa pushed a commit to arewa/aws-cdk that referenced this pull request Oct 8, 2022
aws#22393)

Here's a possible scenario that can lead to "Uploaded file must be a non-empty zip":

- Bundling starts
- A partial zip file is written
- The process is interrupted (`^C` or similar) while writing.
- On next run, the destination file already exists, is taken to be complete, and uploaded.

In this fix, we'll write the zip to a temporary file and atomically rename it into place once finished, thereby avoiding this possible scenario.

Attempts to fix aws#18459.

I don't have tests for this, I don't know how to write them properly. To my mind, if the code looks good and we pass integration tests, that should be sufficient. Add a global asset salting mechanism so that we know all asset hashes are always unique.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
homakk pushed a commit to homakk/aws-cdk that referenced this pull request Dec 1, 2022
aws#22393)

Here's a possible scenario that can lead to "Uploaded file must be a non-empty zip":

- Bundling starts
- A partial zip file is written
- The process is interrupted (`^C` or similar) while writing.
- On next run, the destination file already exists, is taken to be complete, and uploaded.

In this fix, we'll write the zip to a temporary file and atomically rename it into place once finished, thereby avoiding this possible scenario.

Attempts to fix aws#18459.

I don't have tests for this, I don't know how to write them properly. To my mind, if the code looks good and we pass integration tests, that should be sufficient. Add a global asset salting mechanism so that we know all asset hashes are always unique.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
rix0rrr added a commit that referenced this pull request Dec 1, 2022
I'm pretty sure that the correct fix for the issue this debug text was attempting to help debug was delivered in #22393

Get rid of the warning message, it only serves to confuse.
mergify bot pushed a commit that referenced this pull request Dec 2, 2022
I'm pretty sure that the correct fix for the issue this debug text was attempting to help debug was delivered in #22393

Get rid of the warning message, it only serves to confuse.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Dec 9, 2022
I'm pretty sure that the correct fix for the issue this debug text was attempting to help debug was delivered in aws#22393

Get rid of the warning message, it only serves to confuse.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Jan 20, 2023
I'm pretty sure that the correct fix for the issue this debug text was attempting to help debug was delivered in aws#22393

Get rid of the warning message, it only serves to confuse.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
brennanho pushed a commit to brennanho/aws-cdk that referenced this pull request Feb 22, 2023
I'm pretty sure that the correct fix for the issue this debug text was attempting to help debug was delivered in aws#22393

Get rid of the warning message, it only serves to confuse.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. p1 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(aws-lambda-nodejs): Uploaded file must be a non-empty zip
4 participants