diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 13:18:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 13:18:25 +0000 |
commit | 109be507377fe7f6e8819ac94041d3fdcdf6fd2f (patch) | |
tree | 2806a689f8fab4a2ec9fc949830ef270a91d667d /src/os/rlimit.go | |
parent | Initial commit. (diff) | |
download | golang-1.19-109be507377fe7f6e8819ac94041d3fdcdf6fd2f.tar.xz golang-1.19-109be507377fe7f6e8819ac94041d3fdcdf6fd2f.zip |
Adding upstream version 1.19.8.upstream/1.19.8upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/os/rlimit.go')
-rw-r--r-- | src/os/rlimit.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/os/rlimit.go b/src/os/rlimit.go new file mode 100644 index 0000000..a89414d --- /dev/null +++ b/src/os/rlimit.go @@ -0,0 +1,32 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris + +package os + +import "syscall" + +// 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. +func init() { + var lim syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max { + lim.Cur = lim.Max + adjustFileLimit(&lim) + syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim) + } +} |