Skip to content

Conversation

sobolk
Copy link
Contributor

@sobolk sobolk commented May 11, 2023

Description of changes

Pipes the file instead of buffering in memory at binary installation.

Issue #, if available

Description of how you validated changes

E2E tests. I.e. amplify_sudo_install_test

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

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

Comment on lines 156 to 171
extract.on('entry', (header, extractStream, next) => {
if (header.type === 'file') {
extractStream.on('data', (chunk) => {
chunks.push(chunk);
const fileWriteStream = fs.createWriteStream(this.binaryPath, {
mode: 0o755,
});
extractStream.pipe(fileWriteStream);
}
extractStream.on('end', () => {
next();
});

extractStream.resume();
});
extract.on('finish', () => {
if (chunks.length) {
const data = Buffer.concat(chunks);
fs.writeFileSync(this.binaryPath, data, {
mode: 0o755,
});
}
});
return extract;
}
}
Copy link
Contributor Author

@sobolk sobolk May 11, 2023

Choose a reason for hiding this comment

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

there's strong assumption in this code that TAR has only one file.
In both old and new version.

edwardfoyle
edwardfoyle previously approved these changes May 11, 2023
Comment on lines +457 to +460
# limit memory for new processes to 1GB
# this is to make sure that install can work on small VMs
# i.e. not buffer content in memory while installing binary
ulimit -Sv 1000000
Copy link
Contributor Author

Choose a reason for hiding this comment

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

12.0.0 release
image

After applying fix
image

Copy link
Contributor

Choose a reason for hiding this comment

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

nice

@sobolk sobolk marked this pull request as ready for review May 12, 2023 04:42
@sobolk sobolk requested a review from a team as a code owner May 12, 2023 04:42
// Dummy array to collect a promise from nested pipeline that extracts tar content to a file.
const extractPromiseCollector: Array<Promise<void>> = [];
await pipeline(res.data, createGunzip(), this.extract(extractPromiseCollector));
await extractPromiseCollector[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

why only await the first promise and not Promise.allSettled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we get here there's only one promise, but Promise.all would do too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. I used Promise.all not Promise.allSettled . This should throw if extracting fails.

@codecov-commenter
Copy link

codecov-commenter commented May 12, 2023

Codecov Report

Merging #12621 (1655240) into dev (ec9a2ba) will increase coverage by 47.58%.
The diff coverage is 49.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@             Coverage Diff             @@
##              dev   #12621       +/-   ##
===========================================
+ Coverage    0.00%   47.58%   +47.58%     
===========================================
  Files        1296      843      -453     
  Lines      149743    38364   -111379     
  Branches     1296     7846     +6550     
===========================================
+ Hits            0    18256    +18256     
+ Misses     148447    18477   -129970     
- Partials     1296     1631      +335     
Impacted Files Coverage Δ
...ify-category-function/src/events/prePushHandler.ts 33.33% <0.00%> (+33.33%) ⬆️
...lify-category-hosting/lib/S3AndCloudFront/index.js 89.65% <ø> (+89.65%) ⬆️
...s/amplify-cli-core/src/errors/amplify-exception.ts 82.35% <ø> (+82.35%) ⬆️
packages/amplify-cli-core/src/types.ts 100.00% <ø> (+100.00%) ⬆️
packages/amplify-cli/src/commands/console.ts 0.00% <0.00%> (ø)
...c/extensions/amplify-helpers/auth-notifications.ts 41.00% <4.34%> (+41.00%) ⬆️
...service-walkthroughs/execPermissionsWalkthrough.ts 70.42% <11.11%> (+70.42%) ⬆️
...s/awscloudformation/utils/cloudformationHelpers.ts 11.62% <11.11%> (+11.62%) ⬆️
...udformation/src/utils/remove-dependent-function.ts 12.24% <11.11%> (+12.24%) ⬆️
...dformation/utils/get-oauth-secrets-from-cognito.ts 20.00% <20.00%> (ø)
... and 15 more

... and 1281 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

awsluja
awsluja previously approved these changes May 12, 2023
Copy link
Contributor

@awsluja awsluja left a comment

Choose a reason for hiding this comment

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

looks good, only nit would be to add a note why we had to go this route (spawnSync was executing prematurely because tar.extract callbacks were not being awaited; this approach collects those nested callbacks and forces the process to await all) or something like that

edwardfoyle
edwardfoyle previously approved these changes May 12, 2023
@sobolk sobolk dismissed stale reviews from edwardfoyle and awsluja via 1655240 May 12, 2023 18:23
@sobolk sobolk merged commit 0ee53e6 into aws-amplify:dev May 12, 2023
@sobolk sobolk deleted the stream-binary-content branch May 12, 2023 18:50
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.

4 participants