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

feat: bugfix for artifacts upload #749

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

xueningl-az
Copy link
Contributor

Problem

Node limit for 2 GiB for fs.readFile . ‘File size is greater than 2 GiB’ is common error in node with fs.readFile.
Reference nodejs/node#55864

We are using fs.readFile in 3 places in language server code.

Solution

use fs.createReadStream instead.

License

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

@xueningl-az xueningl-az requested a review from a team as a code owner January 24, 2025 20:51
//use fs.createReadStream() to handle the file in smaller, manageable chunks rather than loading the entire file
// into memory. This avoids hitting the 2 GiB limit that occurs when using fs.readFile(),
// as it loads the entire file into memory.
static async getSha256(fileName: string): Promise<string> {

Choose a reason for hiding this comment

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

Rename to getSha256Async

@@ -199,10 +212,17 @@ export class ArtifactManager {
})
}

calculateMD5Sync(filePath: string): string {
async calculateMD5Sync(filePath: string): Promise<string> {

Choose a reason for hiding this comment

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

  1. Rename to calculateMD5Async
  2. Do we need to await any calls to this function now that it is async?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only place

const response = await got.put(resp.uploadUrl, {
body: fs.readFileSync(fileName),
body: fileStream,

Choose a reason for hiding this comment

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

Does this work? Seems like got has a separate API for streams

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's working for stream.

Copy link
Contributor

Choose a reason for hiding this comment

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

got is not browser-compatible. In the vscode extension we settled on cross-fetch, and are using a wrapper so that modules can avoid direct dependencies on whatever package we use: https://github.com/aws/aws-toolkit-vscode/blob/2200b1544d0c0c3e250b8ae2dc16d5f3e87c4270/packages/core/src/shared/request.ts#L6

@pranav-firake
Copy link
Contributor

CI build is failing with message AssertError: expected readFileSync to be called once but was called 0 times
we will need to update test too

@pranav-firake pranav-firake changed the title feat: bugfix for artifacts upload [internal review] feat: bugfix for artifacts upload Jan 27, 2025
@xueningl-az xueningl-az requested a review from jonlouie January 27, 2025 23:27
//use fs.createReadStream() to handle the file in smaller, manageable chunks rather than loading the entire file
// into memory. This avoids hitting the 2 GiB limit that occurs when using fs.readFile(),
// as it loads the entire file into memory.
static async getSha256Async(fileName: string): Promise<string> {
Copy link
Contributor

Choose a reason for hiding this comment

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

As a small optimization, is it possible/sensible to calculate the sha256 and md5 of files at the same time and store these details in the artifact manager, that way we can get rid of some extra overhead by reducing the number of times fsCreateReadStream gets called on a single file.

If the timing of these hash calculations matters and if such an optimization is not feasible, feel free to ignore this comment

@pranav-firake pranav-firake changed the title [internal review] feat: bugfix for artifacts upload feat: bugfix for artifacts upload Jan 28, 2025
@pranav-firake pranav-firake merged commit 71c0a19 into main Jan 28, 2025
6 checks passed
@pranav-firake pranav-firake deleted the bugfix-netTransform-artifacts-readFile branch January 28, 2025 17:48
pranav-firake pushed a commit that referenced this pull request Jan 31, 2025
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.

6 participants