Skip to content

Commit

Permalink
Check that info.NCPU is not zero (#29302) (#29889)
Browse files Browse the repository at this point in the history
## What does this PR do?

This adds a check for 0 when determining the concurrency limit used by mage during a build.

## Why is it important?

`docker info -f '{{ json .}}'` exits with 0 even if there was an error, so the check for `err == nil` doesn't catch errors, and the default int value of 0 is used when trying to read `info.NCPU`. This leads to the confusing behaviour where the build stops and hangs forever with no errors and no indication that anything has gone wrong unless you build with --verbose.

(cherry picked from commit 10f850e)

Co-authored-by: Maxwell Borden <Tacklebox@users.noreply.github.com>
  • Loading branch information
mergify[bot] and Tacklebox committed Jan 18, 2022
1 parent 18376a8 commit 9510d24
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dev-tools/mage/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ func numParallel() int {
maxParallel := runtime.NumCPU()

info, err := GetDockerInfo()
if err == nil && info.NCPU < maxParallel {
// Check that info.NCPU != 0 since docker info doesn't return with an
// error status if communcation with the daemon failed.
if err == nil && info.NCPU != 0 && info.NCPU < maxParallel {
maxParallel = info.NCPU
}

Expand Down

0 comments on commit 9510d24

Please sign in to comment.