From 4ae6ad3247615b49f0a3653404f260ce119e3cb3 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 21 Feb 2020 16:25:13 +0000 Subject: [PATCH] Bug 1616790 - Keep the hard limit for `ulimit -n` unchanged. r=froydnj The hard limit prevents program to set a value higher than the soft limit for themselves, and it turns out Firefox does that. Also, keep the soft limit to its original value if it was already less than 1024. Differential Revision: https://phabricator.services.mozilla.com/D63623 --HG-- extra : moz-landing-system : lando --- taskcluster/scripts/run-task | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/taskcluster/scripts/run-task b/taskcluster/scripts/run-task index c06034a8f7c8..e22f083a2078 100755 --- a/taskcluster/scripts/run-task +++ b/taskcluster/scripts/run-task @@ -692,8 +692,20 @@ def main(args): # Processes spawned by this one will inherit the limit set here. try: import resource - limit = int(os.environ.get('MOZ_LIMIT_NOFILE', '1024')) - resource.setrlimit(resource.RLIMIT_NOFILE, (limit, limit)) + # Keep the hard limit the same, though, allowing processes to change their + # soft limit if they need to (Firefox does, for instance). + (soft, hard) = resource.getrlimit(resource.RLIMIT_NOFILE) + limit = os.environ.get('MOZ_LIMIT_NOFILE') + if limit: + limit = int(limit) + else: + # If no explicit limit is given, use 1024 if it's less than the current + # soft limit. For instance, the default on macOS is 256, so we'd pick + # that rather than 1024. + limit = min(soft, 1024) + # Now apply the limit, if it's different from the original one. + if limit != soft: + resource.setrlimit(resource.RLIMIT_NOFILE, (limit, hard)) except ImportError: # The resource module is UNIX only. pass