Skip to content

Commit 395b03a

Browse files
committed
issue #549: fix setrlimit() crash and hard-wire OS X default
OS X advertised unlimited, but really it means kern.maxfilesperproc.
1 parent c9d890b commit 395b03a

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

ansible_mitogen/process.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,22 @@ def increase_open_file_limit():
246246
limit is much higher.
247247
"""
248248
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
249-
if soft < hard:
250-
LOG.debug('raising soft open file limit from %d to %d', soft, hard)
251-
resource.setrlimit(resource.RLIMIT_NOFILE, (hard, hard))
252-
else:
253-
LOG.debug('cannot increase open file limit; existing limit is %d', hard)
249+
LOG.debug('inherited open file limits: soft=%d hard=%d', soft, hard)
250+
if soft >= hard:
251+
LOG.debug('max open files already set to hard limit: %d', hard)
252+
return
253+
254+
# OS X is limited by kern.maxfilesperproc sysctl, rather than the
255+
# advertised unlimited hard RLIMIT_NOFILE. Just hard-wire known defaults
256+
# for that sysctl, to avoid the mess of querying it.
257+
for value in (hard, 10240):
258+
try:
259+
resource.setrlimit(resource.RLIMIT_NOFILE, (value, hard))
260+
LOG.debug('raised soft open file limit from %d to %d', soft, value)
261+
break
262+
except ValueError as e:
263+
LOG.debug('could not raise soft open file limit from %d to %d: %s',
264+
soft, value, e)
254265

255266

256267
def common_setup(enable_affinity=True, _init_logging=True):

0 commit comments

Comments
 (0)