From 791db70635b780d9e75b78664cc4713654ddd3d0 Mon Sep 17 00:00:00 2001 From: Battleplus <3559424769@qq.com> Date: Mon, 24 Aug 2026 13:13:03 +0800 Subject: [PATCH] fix(docker): handle cgroup v2 'max' in memory guard (#2123) On cgroup v2 with no container memory limit, memory.max contains the string "max". int("max") raised ValueError, the bare except caught it, and the function returned host memory percentage instead of container's. Parse limit as string first, handle "max" explicitly, then fall back to int conversion for numeric values. Closes #2123 --- deploy/docker/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/deploy/docker/utils.py b/deploy/docker/utils.py index 8f8ecb180..2b7d7424e 100644 --- a/deploy/docker/utils.py +++ b/deploy/docker/utils.py @@ -420,9 +420,16 @@ def get_container_memory_percent() -> float: limit_path = Path("/sys/fs/cgroup/memory/memory.limit_in_bytes") usage = int(usage_path.read_text()) - limit = int(limit_path.read_text()) + limit_str = limit_path.read_text().strip() - # Handle unlimited (v2: "max", v1: > 1e18) + # Handle unlimited: cgroup v2 writes "max", cgroup v1 writes > 1e18 + if limit_str == "max" or not limit_str: + import psutil + limit = psutil.virtual_memory().total + else: + limit = int(limit_str) + + # Handle cgroup v1 unlimited (limit > 1e18) if limit > 1e18: import psutil limit = psutil.virtual_memory().total