From 7e971cf4590407f665e71bd59473d33197f2a3c5 Mon Sep 17 00:00:00 2001 From: jonathanrainer Date: Wed, 16 Oct 2024 06:48:40 +0100 Subject: [PATCH] FLEET-19 Fix /proc/filesystems query to be more resilient --- apollo-router/src/plugins/fleet_detector.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/apollo-router/src/plugins/fleet_detector.rs b/apollo-router/src/plugins/fleet_detector.rs index 8c8978cb0e5..4849567f368 100644 --- a/apollo-router/src/plugins/fleet_detector.rs +++ b/apollo-router/src/plugins/fleet_detector.rs @@ -49,21 +49,21 @@ fn detect_cpu_count(system: &System) -> u64 { let system_cpus = system.cpus().len() as u64; // Grab the contents of /proc/filesystems - let filesystems_file = fs::read_to_string("/proc/filesystems").unwrap(); - // Parse the list and only take the first column, filtering to elements that contain - // 'cgroups' - let fses: HashSet<&str> = filesystems_file - .split('\n') - .map(|x| x.split_whitespace().next().unwrap()) - .filter(|x| x.contains("cgroup")) - .collect(); + let fses: HashSet<&str> = match fs::read_to_string("/proc/filesystems") { + Ok(content) => content + .lines() + .map(|x| x.split_whitespace().next().unwrap_or("")) + .filter(|x| x.contains("cgroup")) + .collect(), + Err(_) => return system_cpus, + }; if fses.contains("cgroup2") { // If we're looking at cgroup2 then we need to look in `cpu.max` match fs::read_to_string("/sys/fs/cgroup/cpu.max") { Ok(readings) => { // The format of the file lists the quota first, followed by the period, - // but the quote could also be max which would mean there are no restrictions. + // but the quota could also be max which would mean there are no restrictions. if readings.starts_with("max") { system_cpus } else {