GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing github.com — Account for existing but empty `cpus` file by angelapwen · Pull Request #2151 · github/codeql-action Conversation
|
| 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(); |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| const cpusString = fs.readFileSync(cpusFile, "utf-8").trim(); | ||
| for (const token of cpusString.split(",")) { | ||
| if (!token.includes("-")) { | ||
| if (token.length > 0 && !token.includes("-")) { |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
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.
8275137 to
ef0a773
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
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.
There was an error while loading. Please reload this page.