From 62baa48ef56d4a2889703bb55358ca6b03ed4ff3 Mon Sep 17 00:00:00 2001 From: Anastassios Nanos Date: Tue, 7 Sep 2021 21:38:52 +0000 Subject: [PATCH] virtcontainers: fc: parse vcpuID correctly In getThreadIDs(), the cpuID variable is derived from a string that already contains a whitespace. As a result, strings.SplitAfter returns the cpuID with a leading space. This makes any go variant of string to int fail (strconv.ParseInt() in our case). This patch makes sure that the leading space character is removed so the string passed to strconv.ParseInt() is "CPUID" and not " CPUID". This has been caused by a change in the naming scheme of vcpu threads for Firecracker after v0.19.1. Fixes: #2592 Signed-off-by: Anastassios Nanos --- src/runtime/virtcontainers/fc.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/runtime/virtcontainers/fc.go b/src/runtime/virtcontainers/fc.go index f3002ee44e..5e8fd6cb3f 100644 --- a/src/runtime/virtcontainers/fc.go +++ b/src/runtime/virtcontainers/fc.go @@ -1170,7 +1170,11 @@ func (fc *firecracker) getThreadIDs(ctx context.Context) (vcpuThreadIDs, error) if len(cpus) != 2 { return vcpuInfo, errors.Errorf("Invalid fc thread info: %v", comm) } - cpuID, err := strconv.ParseInt(cpus[1], 10, 32) + + //Remove the leading whitespace + cpuIdStr := strings.TrimSpace(cpus[1]) + + cpuID, err := strconv.ParseInt(cpuIdStr, 10, 32) if err != nil { return vcpuInfo, errors.Wrapf(err, "Invalid fc thread info: %v", comm) }