diff options
author | Andrei Vagin <avagin@google.com> | 2020-10-20 21:43:01 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-10-20 21:44:51 -0700 |
commit | b6a0c91aa16a06d8c7f8316919491290c8890be7 (patch) | |
tree | be430d17a0809664621bed3d3768f9c2d2ef0367 /test/runtimes/proctor | |
parent | 7dc108b41f59ad750f987861d0bda09217916ccb (diff) |
test/runtime: set the NOFILE soft rlimit to 32K
The python:test_subprocess enumerates all possible file descriptors and fails
by timeout if the limit is too high.
There is a know thing about docker that it sets this limit to 1M by default,
but on native linux, this limit will be between 1K to 32K.
PiperOrigin-RevId: 338197239
Diffstat (limited to 'test/runtimes/proctor')
-rw-r--r-- | test/runtimes/proctor/main.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/runtimes/proctor/main.go b/test/runtimes/proctor/main.go index e5607ac92..81cb68381 100644 --- a/test/runtimes/proctor/main.go +++ b/test/runtimes/proctor/main.go @@ -22,6 +22,7 @@ import ( "log" "os" "strings" + "syscall" "gvisor.dev/gvisor/test/runtimes/proctor/lib" ) @@ -33,6 +34,29 @@ var ( pause = flag.Bool("pause", false, "cause container to pause indefinitely, reaping any zombie children") ) +// setNumFilesLimit changes the NOFILE soft rlimit if it is too high. +func setNumFilesLimit() error { + // In docker containers, the default value of the NOFILE limit is + // 1048576. A few runtime tests (e.g. python:test_subprocess) + // enumerates all possible file descriptors and these tests can fail by + // timeout if the NOFILE limit is too high. On gVisor, syscalls are + // slower so these tests will need even more time to pass. + const nofile = 32768 + rLimit := syscall.Rlimit{} + err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit) + if err != nil { + return fmt.Errorf("failed to get RLIMIT_NOFILE: %v", err) + } + if rLimit.Cur > nofile { + rLimit.Cur = nofile + err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) + if err != nil { + return fmt.Errorf("failed to set RLIMIT_NOFILE: %v", err) + } + } + return nil +} + func main() { flag.Parse() @@ -74,6 +98,10 @@ func main() { tests = strings.Split(*testNames, ",") } + if err := setNumFilesLimit(); err != nil { + log.Fatalf("%v", err) + } + // Run tests. cmds := tr.TestCmds(tests) for _, cmd := range cmds { |