-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: syscall: document Setrlimit behavior change on Go 1.12 on macOS #30401
Comments
CC @randall77 |
Yes, this is unfortunate. We switched to using the implementation of
I suppose we could make our implementation of You can always binary search for the largest allowable value. Yuck. |
Note that this is not just a Go problem - C people run into similar issues: https://postfix-devel.postfix.narkive.com/kVL334x7/mac-os-x-and-setrlimit-2 |
Ah yes, I wasn't particularly complaining that Go is doing something wrong (given the restrictions), just trying to figure out what the best solution is. I guess my main complaint wasn't that Go works one way or the other, rather that it changed it behavior, breaking existing code. We can fix it to handle both cases (i.e. hard code that magic number), just would like to know which solution will Go stay with in the end so we don't have to do a 3rd fixup round for Go 1.12.1 :) |
Going forward on Darwin Go is always going to call the C function. |
I found that on Go 1.11.5, this code:
reports The manpage says: I searched for OPEN_MAX in /Application/Xcode.app and found that it is 10240, even though the observed behavior is 24576 works. 🤷♂️ |
@jeffallen What Mac OS are you running? |
Here is an excellent explanation: https://unix.stackexchange.com/questions/350776/setting-os-x-macos-bsd-maxfile It says this could be a problem on FreeBSD and OpenBSD as well. Another useful reference, showing that reading the setrlimit manpage and paying any attention whatsoever to OPEN_MAX would be not a good idea: https://julio.meroh.net/2019/01/open-files-limit-macos-and-the-jvm.html |
For what it's worth; On my Mojave This can be set for the current session with something ala: sudo launchctl limit maxfiles 1234 200000 In the above example, I get If I run |
Summary: This commit implements a workaround to an issue [[ golang/go#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
… ...) on Darwin. It turns out rlim_max from getrlimit(RLIMIT_NOFILE, ...) is not a valid value for rlim_cur in setrlimit(RLIMIT_NOFILE, ...) on Darwin. Golang used to silently fix this for us, but it stopped doing it. See golang/go#30401. Take reasonable steps to work around it for now.
Change https://golang.org/cl/188237 mentions this issue: |
Change https://golang.org/cl/188357 mentions this issue: |
…mit behavior Fixes #30401 Change-Id: I7b5035ffc7333c746d4e31563df26ff4f934dfc6 Reviewed-on: https://go-review.googlesource.com/c/go/+/188237 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Keith Randall <khr@golang.org> (cherry picked from commit fe8a866) Reviewed-on: https://go-review.googlesource.com/c/go/+/188357
I experienced the same. Found that sysctl kern.maxfilesperproc was set to 24576. I increased kern.maxfilesperproc and was able to increase rLimit.Cur to the new value. This was in Mojave 10.14.6 |
Running on osx, the attempt to change the rlimit fails with "invalid argument". It appears that the value of rlimit.Max is `9223372036854775807`, and that trying to set to that value fails. More on this at golang/go#30401. We fix this by setting the value to the somewhat magic 24576 when on osx (darwin).
Running on osx, the attempt to change the rlimit fails with "invalid argument". It appears that the value of rlimit.Max is `9223372036854775807`, and that trying to set to that value fails. More on this at golang/go#30401. We fix this by setting the value to the somewhat magic 24576 when on osx (darwin).
Running on osx, the attempt to change the rlimit fails with "invalid argument". It appears that the value of rlimit.Max is `9223372036854775807`, and that trying to set to that value fails. More on this at golang/go#30401. We fix this by setting the value to the somewhat magic 24576 when on osx (darwin).
We've noticed a while back that when setting the file descriptor allowance on macos, Go restricts it to a lower value than requested:
The above code on Linux works as expected, setting the limit to the max returned by the syscall package.
On macos with Go 1.11.5 (and prior) it silently set it to the minimum of
limit.Max
and 10240. We had to patch our code to explicitly check the actual value set instead of relying on no-error-returned since we falsely alloted more fds to databases than available.On macos with Go 1.12, our code again started to blow up, now returning
invalid argument
errors instead of the silent capping previously.I'd probably say both behaviors are bad, but the new one is a lot worse than the previous. Now it only tells us it's invalid, but unless you know the magic number defined in the your own kernel version, there's no way for user code to figure out how many fds are actually available.
The text was updated successfully, but these errors were encountered: