From 083d28ce9ce3e0e5ce48f354e6e70690b7fabb18 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 11 Feb 2026 21:38:02 +0100 Subject: [PATCH] Increase the open file soft limit to the hard limit On some platforms (macOS), the default soft limit is very low, but the hard limit is high. So let's just raise it the maximum permitted. --- src/libmain/shared.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index cac9e38ad857..815c60cf82f3 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #ifdef __linux__ @@ -116,6 +117,26 @@ std::string getArg(const std::string & opt, Strings::iterator & i, const Strings static void sigHandler(int signo) {} #endif +/** + * Increase the open file soft limit to the hard limit. On some + * platforms (macOS), the default soft limit is very low, but the hard + * limit is high. So let's just raise it the maximum permitted. + */ +void bumpFileLimit() +{ +#ifndef _WIN32 + struct rlimit limit; + if (getrlimit(RLIMIT_NOFILE, &limit) != 0) + return; + + if (limit.rlim_cur < limit.rlim_max) { + limit.rlim_cur = limit.rlim_max; + // Ignore errors, this is best effort. + setrlimit(RLIMIT_NOFILE, &limit); + } +#endif +} + void initNix(bool loadConfig) { /* Turn on buffering for cerr. */ @@ -183,6 +204,8 @@ void initNix(bool loadConfig) now. In particular, store objects should be readable by everybody. */ umask(0022); + + bumpFileLimit(); } LegacyArgs::LegacyArgs(