From 2e7c07f4d10c1b391a7138471c49f4aae3c47d8d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 31 Jul 2025 11:54:57 +0200 Subject: [PATCH] linux: handle cgroups cpu.max with limit < period (#4853) This apparently manifests when one passes `--cpu=.5` to docker because then /sys/fs/cgroup/cpu.max looks like `50000 100000`, and 50000 divided by 100000 is zero when using integer math. Return 1 in that case, indicating there is at least one CPU available. Returning 0 makes no sense because there is always at least one CPU available, otherwise the program wouldn't be running. Fixes: https://github.com/nodejs/node/issues/59200 --- src/unix/linux.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/unix/linux.c b/src/unix/linux.c index 1a62d78df..4bfb2d2e7 100644 --- a/src/unix/linux.c +++ b/src/unix/linux.c @@ -2363,6 +2363,8 @@ static int uv__get_cgroupv2_constrained_cpu(const char* cgroup, goto next; *quota = limit / period; + if (*quota == 0) + *quota = 1; if (*quota < min_quota) min_quota = *quota;