Skip to content

Commit

Permalink
Catch exceptions during file read. (#10623)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivialfis authored Jul 22, 2024
1 parent a19bbc9 commit 485d902
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/common/threading_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,26 @@ std::int32_t GetCGroupV2Count(std::filesystem::path const& bandwidth_path) noexc

std::int32_t GetCfsCPUCount() noexcept {
namespace fs = std::filesystem;
fs::path const bandwidth_path{"/sys/fs/cgroup/cpu.max"};
auto has_v2 = fs::exists(bandwidth_path);
if (has_v2) {
return GetCGroupV2Count(bandwidth_path);

try {
fs::path const bandwidth_path{"/sys/fs/cgroup/cpu.max"};
auto has_v2 = fs::exists(bandwidth_path);
if (has_v2) {
return GetCGroupV2Count(bandwidth_path);
}
} catch (std::exception const&) {
return -1;
}

fs::path const quota_path{"/sys/fs/cgroup/cpu/cpu.cfs_quota_us"};
fs::path const peroid_path{"/sys/fs/cgroup/cpu/cpu.cfs_period_us"};
auto has_v1 = fs::exists(quota_path) && fs::exists(peroid_path);
if (has_v1) {
return GetCGroupV1Count(quota_path, peroid_path);
try {
fs::path const quota_path{"/sys/fs/cgroup/cpu/cpu.cfs_quota_us"};
fs::path const peroid_path{"/sys/fs/cgroup/cpu/cpu.cfs_period_us"};
auto has_v1 = fs::exists(quota_path) && fs::exists(peroid_path);
if (has_v1) {
return GetCGroupV1Count(quota_path, peroid_path);
}
} catch (std::exception const&) {
return -1;
}

return -1;
Expand Down

0 comments on commit 485d902

Please sign in to comment.