diff --git a/changelog/@unreleased/pr-321.v2.yml b/changelog/@unreleased/pr-321.v2.yml new file mode 100644 index 00000000..e976ea6e --- /dev/null +++ b/changelog/@unreleased/pr-321.v2.yml @@ -0,0 +1,5 @@ +type: fix +fix: + description: Fix cpu.shares content parsing + links: + - https://github.com/palantir/go-java-launcher/pull/321 diff --git a/launchlib/processors.go b/launchlib/processors.go index c3e1a5e0..4bccc35f 100644 --- a/launchlib/processors.go +++ b/launchlib/processors.go @@ -67,7 +67,7 @@ func (c CGroupV1ProcessorCounter) ProcessorCount() (uint, error) { if err != nil { return 0, errors.Wrapf(err, "unable to read cpu.shares") } - cpuShares, err := strconv.Atoi(string(cpuShareBytes)) + cpuShares, err := strconv.Atoi(strings.TrimSpace(string(cpuShareBytes))) if err != nil { return 0, errors.New("unable to convert cpu.shares value to expected type") } diff --git a/launchlib/processors_test.go b/launchlib/processors_test.go index efcad816..c2e84326 100644 --- a/launchlib/processors_test.go +++ b/launchlib/processors_test.go @@ -88,8 +88,8 @@ var ( 3473 5088 0:435 / /proc/scsi ro,relatime - tmpfs tmpfs ro 3474 5092 0:436 / /sys/firmware ro,relatime - tmpfs tmpfs ro`) - lowCPUSharesContent = []byte(`100`) - highCPUSharesContent = []byte(`10000`) + lowCPUSharesContent = []byte("100\n") + highCPUSharesContent = []byte("10000\n") badCPUSharesContent = []byte(``) )