Skip to content

x/sys/unix: Getrlimit should support RLIMIT_NPROC (number of process limits) #14854

@mithro

Description

@mithro

Under Linux a process can be restricted to the number of threads and processes it can launch at any one time. When hitting the process limit, pthread_create will start failing with EAGAIN which causes the go runtime to abort (see bugs #4056 and #14835).

In #4056 it is mentioned that a user should be managing the number of threads (see Comment 33 #4056 (comment) from @dvyukov)

Users must limit number of threads in sys/cgo calls.

However, different systems can vary widely in the number of threads that you are allowed to create. It is very common on server systems to have a thread limit of 10k, while on desktop and embedded systems it could be as little as 512. Thus the user need to know about the number of threads/processes that an operating system will allow.

Linux provides the ability to read this information using the getrlimit syscall, calling with RLIMIT_NPROC (see http://man7.org/linux/man-pages/man2/getrlimit.2.html). The go runtime already provides access to getrlimit in the syscall.Getrlimit (see https://golang.org/pkg/syscall/#Getrlimit) but this module doesn't currently have the RLIMIT_NPROC resource constant (maybe because it isn't POSIX?).

From the getrlimit man page;

RLIMIT_MEMLOCK and RLIMIT_NPROC derive from BSD and are not specified in POSIX.1-2001; they are present on the BSDs and Linux, but on few other implementations.

I believe this can probably be very easily fixed by changing the regex in mkerrors.sh like shown in this patch here -> https://go-review.googlesource.com/#/c/20751/1/src/syscall/mkerrors.sh

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions