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: Race conditions with multiple downloads on the same layer #7422

Merged
merged 5 commits into from
Sep 1, 2024

Conversation

dkphm
Copy link
Contributor

@dkphm dkphm commented Aug 29, 2024

Which issue(s) does this change fix?

Why is this change necessary?

Customer reports that when the SAM template contains multiple functions, some shared the same lambda layer, local start-api throw the exception

2024-08-27 09:43:43,083 | Lambda functions containers initialization failed because of [Errno 2] No such file or directory: '/Users/aguro/.aws-sam/layers-pkg/NFTUserLayer-3-ff9c237555.zip'

This is because there was a race condition when multiple layer_downloaders were running to build multiple functions concurrently. Some could finish downloading the file first and remove the .zip file, causing the other one failed to unzip.

How does it address the issue?

The fix is to ask each downloader to download into separate zip file (by adding the thread id to the file name), but the extracted folder remains the same.

What side effects does this change have?

Mandatory Checklist

PRs will only be reviewed after checklist is complete

  • Add input/output type hints to new functions/methods
  • Write design document if needed (Do I need to write a design document?)
  • Write/update unit tests
  • Write/update integration tests
  • Write/update functional tests if needed
  • make pr passes
  • make update-reproducible-reqs if dependencies were changed
  • Write documentation

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

@dkphm dkphm requested a review from a team as a code owner August 29, 2024 21:20
@github-actions github-actions bot added area/local/start-api sam local start-api command area/local/invoke sam local invoke command area/local/start-invoke pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Aug 29, 2024
@dkphm dkphm added pr/internal and removed pr/external stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Aug 29, 2024
@@ -106,7 +107,7 @@ def download(self, layer: LayerVersion, force=False) -> LayerVersion:
LOG.info("%s is already cached. Skipping download", layer.arn)
return layer

layer_zip_path = layer.codeuri + ".zip"
layer_zip_path = f"{layer.codeuri}_{uuid.uuid4().hex}.zip"
layer_zip_uri = self._fetch_layer_uri(layer)
unzip_from_uri(
Copy link
Contributor

@lucashuy lucashuy Aug 30, 2024

Choose a reason for hiding this comment

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

quick question, but will we come across any issues when the Layer is unpacked into the same directory across different threads? I would imagine that this would be fine since the OS controls I/O, but wanted to check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh it should be fine. This is what we want :)

@dkphm dkphm enabled auto-merge August 30, 2024 22:03
@dkphm dkphm added this pull request to the merge queue Aug 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 30, 2024
@dkphm dkphm added this pull request to the merge queue Sep 1, 2024
Merged via the queue into aws:develop with commit 7d0800a Sep 1, 2024
55 checks passed
@dkphm dkphm deleted the layer_downloader branch September 2, 2024 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants