Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 06c6241

Browse files
authored
Port to 2.0.0 - Fix rlimit setting of RLIM_NOFILE on OSX (#14070)
This change fixes an issue with rlimit setting of RLIM_NOFILE. The problem is that the rlim_max that we get from getrlimit is too large and so setting the rlimit_cur to that value fails. The OSX man page for rlimit has a compat note about it, stating that the rlimit_cur needs to be limited to min(OPEN_MAX, rlim_max) if one wants to set it to rlim_max.
1 parent 786e9e1 commit 06c6241

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/pal/src/file/file.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,6 +3682,9 @@ DWORD FILEGetLastErrorFromErrno( void )
36823682
case EIO:
36833683
dwRet = ERROR_WRITE_FAULT;
36843684
break;
3685+
case EMFILE:
3686+
dwRet = ERROR_TOO_MANY_OPEN_FILES;
3687+
break;
36853688
case ERANGE:
36863689
dwRet = ERROR_BAD_PATHNAME;
36873690
break;

src/pal/src/init/pal.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,14 @@ static BOOL INIT_IncreaseDescriptorLimit(void)
10071007
// Set our soft limit for file descriptors to be the same
10081008
// as the max limit.
10091009
rlp.rlim_cur = rlp.rlim_max;
1010+
#ifdef __APPLE__
1011+
// Based on compatibility note in setrlimit(2) manpage for OSX,
1012+
// trim the limit to OPEN_MAX.
1013+
if (rlp.rlim_cur > OPEN_MAX)
1014+
{
1015+
rlp.rlim_cur = OPEN_MAX;
1016+
}
1017+
#endif
10101018
result = setrlimit(RLIMIT_NOFILE, &rlp);
10111019
if (result != 0)
10121020
{

0 commit comments

Comments
 (0)