Stream layer artifact hashing to avoid buffering whole zip#206
Merged
GrahamCampbell merged 2 commits intomainfrom Apr 29, 2026
Merged
Stream layer artifact hashing to avoid buffering whole zip#206GrahamCampbell merged 2 commits intomainfrom
GrahamCampbell merged 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Eliminates an OOM risk in AWS layer packaging by switching layer artifact hashing from buffered reads to a streaming SHA-1 over the layer zip file.
Changes:
- Replace
fs.promises.readFile()-based hashing incompileLayer()with a streaming hash viafs.createReadStream() - Add a unit test to assert streaming behavior (uses
createReadStream, does not usefs.promises.readFile) and to lock in hash equivalence vs the prior buffered approach
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/plugins/aws/package/compile/layers.js | Streams the layer zip into the SHA-1 hash instead of buffering the entire artifact in memory. |
| test/unit/lib/plugins/aws/package/compile/layers.test.js | Adds a regression test that validates streaming is used and the resulting digest matches the prior buffered hashing behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces
fsp.readFile()incompileLayer()with a streaming SHA-1 overfs.createReadStream(). The previous code materialized the entire layer zip in memory before feeding it tocrypto.createHash('sha1'), which remained an OOM risk for large layers after PR #205 fixed the function-artifact and change-detection hashing paths.The hash bytes are unchanged:
crypto.Hash.update()is incremental, soupdate(JSON.stringify(layerForHash))+ per-chunk update(chunk) produces the same digest as a single update of the full buffer. A new unit test locks this in by computing the expected hash with the original buffered shape and asserting equality against the streaming output, while also assertingfs.createReadStreamis used andfs.promises.readFileis not.This addresses the last whole-artifact buffering site flagged during the #189 review.