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"};