From 81c62cab56b93bda4d7c2c4bb22a14e5bbc4f2f9 Mon Sep 17 00:00:00 2001 From: Jaran Charumilind Date: Thu, 21 Mar 2019 14:13:00 -0700 Subject: [PATCH] reflow: Make raising of FD limit work on OS X/Go 1.12 Summary: This commit implements a workaround to an issue [[ https://github.com/golang/go/issues/30401 | introduced in Go 1.12 ]]. The behavior of `Setrlimit` changed to no longer succeed when the requested limit exceeded the maximum. (It used to succeed, clamping the value to the allowed maximum). Test Plan: Manual testing Reviewers: smahadevan, pgopal, marius Reviewed By: marius Maniphest Tasks: T17776 Differential Revision: https://phabricator.grailbio.com/D27211 fbshipit-source-id: 8be13f0 --- tool/main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tool/main.go b/tool/main.go index 3c220777..bba51e4c 100644 --- a/tool/main.go +++ b/tool/main.go @@ -16,6 +16,7 @@ import ( _ "net/http/pprof" "os" "os/signal" + "runtime" "runtime/pprof" "sort" "syscall" @@ -416,6 +417,15 @@ func increaseFDRlimit() error { return nil } l.Cur = l.Max + + // The following is a workaround for this issue: + // https://github.com/golang/go/issues/30401 + if runtime.GOOS == "darwin" && l.Cur > 24576 { + // The max file limit is 24576, even though the max returned by + // Getrlimit is 1<<63-1. + l.Cur = 24576 + } + return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &l) }