@@ -2148,13 +2148,12 @@ jint os::init_2(void) {
21482148
21492149 // On macOS according to setrlimit(2), OPEN_MAX must be used instead
21502150 // of RLIM_INFINITY, but testing on macOS >= 10.6, reveals that
2151- // we can, in fact, use even RLIM_INFINITY, so try the max value
2152- // that the system claims can be used first, same as other BSD OSes.
2153- // However, some terminals (ksh) will internally use "int" type
2154- // to store this value and since RLIM_INFINITY overflows an "int"
2155- // we might end up with a negative value, so cap the system limit max
2156- // at INT_MAX instead, just in case, for everyone.
2157- nbr_files.rlim_cur = MIN (INT_MAX, nbr_files.rlim_max );
2151+ // we can, in fact, use even RLIM_INFINITY.
2152+ // However, we need to limit the value to 0x100000 (which is the max value
2153+ // allowed on Linux) so that any existing code that iterates over all allowed
2154+ // file descriptors, finishes in a reasonable time, without appearing
2155+ // to hang.
2156+ nbr_files.rlim_cur = MIN (0x100000 , nbr_files.rlim_max );
21582157
21592158 status = setrlimit (RLIMIT_NOFILE, &nbr_files);
21602159 if (status != 0 ) {
0 commit comments