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 — Account for existing but empty `cpus` file by angelapwen · Pull Request #2151 · github/codeql-action

Conversation

@angelapwen

@angelapwen angelapwen commented Feb 15, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

If a CPU file exists but is empty, previously we reported this file with a CPU count of 1, which resulted in a single-threaded run.

Fixes #2139.

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.

All reactions
@angelapwen
angelapwen force-pushed the fix-cpu-group-bug branch from dc7e2b5 to 8275137 Compare February 15, 2024 14:36
@angelapwen angelapwen changed the title Account for non-empty cpus file with whitespace chars Account for existing but empty cpus file Feb 15, 2024
@angelapwen angelapwen mentioned this pull request Feb 15, 2024
Executing the CodeQL GitHub Action within a Docker container results in the detection of only a single CPU, due to the /sys/fs/cgroup/cpuset.cpus file being empty. #2139
Closed
@angelapwen
angelapwen marked this pull request as ready for review February 15, 2024 14:42
@angelapwen
angelapwen requested a review from a team as a code owner February 15, 2024 14:42
henrymercer
henrymercer reviewed Feb 15, 2024
View reviewed changes

@henrymercer henrymercer 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.

Thanks for addressing this. Couple of comments, and additionally, could we add a unit test?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread src/util.ts
let cpuCount = 0;
// Comma-separated numbers and ranges, for eg. 0-1,3
const cpusString = fs.readFileSync(cpusFile, "utf-8");
const cpusString = fs.readFileSync(cpusFile, "utf-8").trim();

@henrymercer henrymercer Feb 15, 2024

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.

My understanding is that if the file is empty, we'll return 0, but I think we probably want to return undefined?

Sorry, something went wrong.

Uh oh!

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

All reactions

@angelapwen angelapwen Feb 15, 2024

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.

That could work too — we're filtering out all counts that are undefined, or <= 0, so they kind of have the same meaning. But I don't mind making it return undefined if that's more clear.

Sorry, something went wrong.

Uh oh!

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

All reactions

@henrymercer henrymercer Feb 15, 2024

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, that's good that we were already filtering out <=0. I think I'd find undefined slightly more clear, but it's not critical.

Sorry, something went wrong.

Uh oh!

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

All reactions

@angelapwen angelapwen Feb 16, 2024

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 updated logic returns undefined 😄

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread src/util.ts Outdated
const cpusString = fs.readFileSync(cpusFile, "utf-8").trim();
for (const token of cpusString.split(",")) {
if (!token.includes("-")) {
if (token.length > 0 && !token.includes("-")) {

@henrymercer henrymercer Feb 15, 2024

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 does it mean if the token is empty here? If it's not valid, we might want to log then bail out and return undefined. If it's valid, is the else block doing the right thing?

Sorry, something went wrong.

Uh oh!

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

All reactions

@angelapwen angelapwen Feb 15, 2024

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.

If the file is empty here (or just has a newline character as in the linked issue) the trim should make it an empty string. Then .split() will also just return a single string that's empty. Previously we were incrementing the count because an empty string doesn't include -. You're right that we shouldn't be entering the else block though... we should just be bailing out. I'll update this and look at adding the unit test 👍

Sorry, something went wrong.

Uh oh!

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

henrymercer reacted with heart emoji
All reactions
  • ❤️ 1 reaction

@angelapwen angelapwen Feb 16, 2024

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.

Okay — I added unit tests for the case where the file exists and the number of CPUs should be calculated, the case where the file doesn't exist, and the case where the file exists but only has a newline char in it!

Sorry, something went wrong.

Uh oh!

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

All reactions
@angelapwen
Account for existing but empty cpus file
ef0a773
If a CPU file exists but is empty, previously we reported this file with a CPU count of 1, which resulted in a single-threaded run.
@angelapwen
angelapwen force-pushed the fix-cpu-group-bug branch from 8275137 to ef0a773 Compare February 15, 2024 16:18
@angelapwen
Add unit tests for getCgroupCpuCountFromCpus
8cb81db
@angelapwen
angelapwen requested a review from henrymercer February 16, 2024 13:01
henrymercer
henrymercer approved these changes Feb 16, 2024
View reviewed changes

@henrymercer henrymercer 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.

Nice!

Sorry, something went wrong.

Uh oh!

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

All reactions
@angelapwen
angelapwen merged commit 592977e into github:main Feb 20, 2024
@angelapwen
angelapwen deleted the fix-cpu-group-bug branch February 20, 2024 11:06
This was referenced Feb 21, 2024
Merge main into releases/v3 #2157
Merged
Merge releases/v3 into releases/v2 #2159
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@henrymercer henrymercer henrymercer approved these changes

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.

Executing the CodeQL GitHub Action within a Docker container results in the detection of only a single CPU, due to the /sys/fs/cgroup/cpuset.cpus file being empty.

Uh oh!

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

2 participants

@angelapwen @henrymercer
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.