]> Cypherpunks repositories - gostls13.git/commit
os: raise open file rlimit at startup
authorRuss Cox <rsc@golang.org>
Mon, 14 Mar 2022 15:27:46 +0000 (11:27 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 17 Mar 2022 03:04:30 +0000 (03:04 +0000)
commit8427429c592588af8c49522c76b3e0e0e335d270
tree0496b919e310875c2236966a11717f3ea133f4a5
parentf839aaa22b66bc556fac72f7396082212d2ef45d
os: raise open file rlimit at startup

Some systems set an artificially low soft limit on open file count,
for compatibility with code that uses select and its hard-coded
maximum file descriptor (limited by the size of fd_set).

Go does not use select, so it should not be subject to these limits.
On some systems the limit is 256, which is very easy to run into, even
in simple programs like gofmt when they parallelize walking a file tree.

After a long discussion on go.dev/issue/46279, we decided the best
approach was for Go to raise the limit unconditionally for itself, and
then leave old software to set the limit back as needed. Code that
really wants Go to leave the limit alone can set the hard limit, which
Go of course has no choice but to respect.

Take 2, after CL 392415 was rolled back for macOS and OpenBSD failures.
The macOS failures should be handled by the new call to sysctl("kern.maxfilesperproc"),
and the OpenBSD failures are handled by skipping the test (and filing #51713).

Fixes #46279.

Change-Id: I45c81b94590b447b483018a05ae980b8f02dc5de
Reviewed-on: https://go-review.googlesource.com/c/go/+/393354
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/os/rlimit.go [new file with mode: 0644]
src/os/rlimit_darwin.go [new file with mode: 0644]
src/os/rlimit_stub.go [new file with mode: 0644]
src/os/rlimit_test.go [new file with mode: 0644]