GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix out of memory in hash computation by edoardopirovano · Pull Request #550 · github/codeql-action

Conversation

@edoardopirovano

@edoardopirovano edoardopirovano commented Jun 7, 2021

Copy link
Copy Markdown
Contributor

Closes #528 by making two changes:

  1. As @adityasharad points out, we probably shouldn't try hashing files for results that don't have a line number, since these are probably not source code files. This will reduce the number of files we need to hash, and avoid us trying to hash large files like tarballs.
  2. As @RA80533 points out, we could avoid the OOM even if we do encounter a large file by computing the hash in a streaming manner so that we never need to store the whole thing in memory.

Either change individually would fix the issue above, but having both seems the most robust solution.

Merge / deployment checklist

  • Confirm this change is backwards compatible with existing workflows.
  • Confirm the readme has been updated if necessary.
  • Confirm the changelog has been updated if necessary.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jsjoeio reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@edoardopirovano
Fix out of memory in hash computation
1b05718
aeisenberg
aeisenberg reviewed Jun 7, 2021
View reviewed changes

@aeisenberg aeisenberg left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks great. One more test would be good and then 🚢 .

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/fingerprints.test.ts
"f1b89f20de0d133:1",
"c129715d7a2bc9a3:1",
]
);

@aeisenberg aeisenberg Jun 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think this needs another test that includes a sarif file without line numbers.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@edoardopirovano edoardopirovano Jun 7, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The fingerprinting2.input.sarif test file was already missing line numbers, so that's showing the new behaviour of omitting the fingerprints (see change in expected output). I'm not sure if that was testing any other behaviour that is now being missed, it didn't seem to be doing anything particularly different from the first test case to me.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@aeisenberg aeisenberg Jun 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Ah...yes. Was re yon my phone and didn't see the whole file.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
RA80533
RA80533 reviewed Jun 7, 2021
View reviewed changes
Comment thread src/fingerprints.ts
const readStream = fs.createReadStream(filepath, "utf8");
readStream.on("close", fulfill);
readStream.on("end", () => {
processCharacter(65535);

@RA80533 RA80533 Jun 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

What is 65535?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@edoardopirovano edoardopirovano Jun 7, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It was being appended at the end of the files when computing their fingerprint in the existing code. I don't know quite what its purpose is, but in the interest of keeping the fingerprints the same I think it makes sense to keep it there.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@RA80533 RA80533 Jun 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yeah, it doesn't seem like a reasonable thing to change given that it would affect the hashes. It might be best to move it into a constant so it doesn't remain a magic number in that case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
aeisenberg
aeisenberg approved these changes Jun 7, 2021
View reviewed changes
@edoardopirovano
edoardopirovano merged commit 02e8dcf into github:main Jun 7, 2021
@edoardopirovano
edoardopirovano deleted the fix-oom branch June 7, 2021 14:12
RA80533
RA80533 reviewed Jun 7, 2021
View reviewed changes
Comment thread src/fingerprints.ts
Comment on lines +117 to +127
await new Promise((fulfill) => {
const readStream = fs.createReadStream(filepath, "utf8");
readStream.on("close", fulfill);
readStream.on("end", () => {
processCharacter(65535);
});
readStream.on("data", (data) => {
for (let i = 0; i < data.length; ++i)
processCharacter(data.charCodeAt(i));
});
});

@RA80533 RA80533 Jun 7, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Be careful about mixing async-await and callback patterns. Error handling gets tricky because thrown errors don't necessarily correlate to promise rejections.

In this case, this could be rewritten entirely in async-await like so:

const readStream = fs.createReadStream(filepath, "utf8");

for await (const chunk of readStream) {
  // Handle the chunk
}

processCharacter(65535);

Any potential errors would be caught as normal because synchronous functions would throw and asynchronous functions would be rejected (because of the await).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@RA80533 RA80533 Jun 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Since this appears to be used for iterating over lines, the Readline API could be useful for consuming the stream:

const reader = readline.createInterface({
  input: fs.createReadStream(filepath, "utf8")
});

for await (const line of reader) {
  // Handle the line
}

processCharacter(65535);

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@edoardopirovano edoardopirovano Jun 7, 2021

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the suggestions! I've applied your first one in #550, it is indeed nicer than what I wrote. The second one doesn't quite fit our use case nicely because we actually want the new lines in the hash.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@RA80533 RA80533 Jun 7, 2021

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

[…] we actually want the new lines in the hash.

Good catch. I figured it would contain the line endings since you're able to redirect the stream directly to {stdout|stderr}.write but apparently it doesn't. 🤔

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jsjoeio jsjoeio mentioned this pull request Jun 7, 2021
Revert code-ql-action/upload-sarif coder/code-server#3517
Closed
@edoardopirovano edoardopirovano mentioned this pull request Jun 7, 2021
Some refactoring in fingerprint computation #551
Merged
This was referenced Jun 17, 2021
Merge main into v1 #568
Closed
Merge main into v1 #570
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@aeisenberg aeisenberg aeisenberg approved these changes
+1 more reviewer
@RA80533 RA80533 RA80533 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

codeql-action/upload-sarif - JavaScript heap out of memory

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@edoardopirovano @aeisenberg @RA80533
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.