Skip to content

Commit

Permalink
increase RLIMIT_NOFILE locally on Linux and macOS
Browse files Browse the repository at this point in the history
* closes esy#1057
  • Loading branch information
EduardoRFS committed May 27, 2020
1 parent 23fa821 commit 4648673
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bin/esy.re
Expand Up @@ -2120,6 +2120,8 @@ let commandsConfig = {
};

let () = {
EsyLib.System.ensureMinimumFileDescriptors();

let (defaultCommand, commands) = commandsConfig;

/*
Expand Down
3 changes: 3 additions & 0 deletions esy-lib/System.re
Expand Up @@ -121,6 +121,9 @@ module Arch = {
external checkLongPathRegistryKey: unit => bool =
"esy_win32_check_long_path_regkey";

external ensureMinimumFileDescriptors: unit => unit =
"esy_ensure_minimum_file_descriptors";

let supportsLongPaths = () =>
switch (Sys.win32) {
| false => true
Expand Down
2 changes: 2 additions & 0 deletions esy-lib/System.rei
Expand Up @@ -46,6 +46,8 @@ module Arch: {

let supportsLongPaths: unit => bool;

let ensureMinimumFileDescriptors: unit => unit;

module Environment: {
/** Environment variable separator which is used for $PATH and etc */

Expand Down
2 changes: 1 addition & 1 deletion esy-lib/dune
Expand Up @@ -9,7 +9,7 @@
EsyShellExpansion)
(foreign_stubs
(language c)
(names win32_path))
(names unix_rlimit_patch win32_path))
(preprocess
(pps lwt_ppx ppx_let ppx_deriving_yojson ppx_deriving.std ppx_expect
ppx_inline_test ppx_sexp_conv)))
Expand Down
20 changes: 20 additions & 0 deletions esy-lib/unix_rlimit_patch.c
@@ -0,0 +1,20 @@
#include <caml/mlvalues.h>

#if __APPLE__ || __linux__
#include <sys/resource.h>
#endif

#define MIN_NOFILE 4096

CAMLprim value
esy_ensure_minimum_file_descriptors(value unit) {
#if __APPLE__ || __linux__
struct rlimit limits;
getrlimit(RLIMIT_NOFILE, &limits);
if (limits.rlim_cur < MIN_NOFILE) {
limits.rlim_cur = MIN_NOFILE;
setrlimit(RLIMIT_NOFILE, &limits);
}
#endif
return Val_unit;
}

0 comments on commit 4648673

Please sign in to comment.