From d8bda6feb491f571acf476314ce7de81a431453f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Mon, 14 Aug 2023 15:05:27 -0700 Subject: [PATCH] replay: increase file descriptor limit macOS (#29346) * Increase file descriptor limit for replay on macos * Reword comment * Move set_file_descriptor_limit to common/util.cc * Include resource.h header --- common/util.cc | 15 +++++++++++++++ common/util.h | 1 + tools/replay/main.cc | 5 +++++ 3 files changed, 21 insertions(+) diff --git a/common/util.cc b/common/util.cc index dca3467c97..6ad619c35c 100644 --- a/common/util.cc +++ b/common/util.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -60,6 +61,20 @@ int set_core_affinity(std::vector cores) { #endif } +int set_file_descriptor_limit(uint64_t limit_val) { + struct rlimit limit; + int status; + + if ((status = getrlimit(RLIMIT_NOFILE, &limit)) < 0) + return status; + + limit.rlim_cur = limit_val; + if ((status = setrlimit(RLIMIT_NOFILE, &limit)) < 0) + return status; + + return 0; +} + std::string read_file(const std::string& fn) { std::ifstream f(fn, std::ios::binary | std::ios::in); if (f.is_open()) { diff --git a/common/util.h b/common/util.h index 4347dfba3b..aaa54d52a2 100644 --- a/common/util.h +++ b/common/util.h @@ -44,6 +44,7 @@ namespace util { void set_thread_name(const char* name); int set_realtime_priority(int level); int set_core_affinity(std::vector cores); +int set_file_descriptor_limit(uint64_t limit); // ***** Time helpers ***** struct tm get_time(); diff --git a/tools/replay/main.cc b/tools/replay/main.cc index 78be2acd0b..98a0bb3333 100644 --- a/tools/replay/main.cc +++ b/tools/replay/main.cc @@ -6,6 +6,11 @@ #include "tools/replay/replay.h" int main(int argc, char *argv[]) { +#ifdef __APPLE__ + // With all sockets opened, we might hit the default limit of 256 on macOS + util::set_file_descriptor_limit(1024); +#endif + QCoreApplication app(argc, argv); const QStringList base_blacklist = {"uiDebug", "userFlag"};