Skip to content

Commit

Permalink
clean cached rlimit nofile in go runtime
Browse files Browse the repository at this point in the history
Signed-off-by: ls-ggg <335814617@qq.com>
  • Loading branch information
ls-ggg committed Mar 29, 2024
1 parent a1acca9 commit 8e3496c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libcontainer/setns_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func (l *linuxSetnsInit) Init() error {
}
}
}

utils.CleanRlimitNoFileCache()

if l.config.CreateConsole {
if err := setupConsole(l.consoleSocket, l.config, false); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions libcontainer/standard_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func (l *linuxStandardInit) Init() error {
}
}

utils.CleanRlimitNoFileCache()

if err := setupNetwork(l.config); err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions libcontainer/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
"unsafe"

"golang.org/x/sys/unix"
Expand Down Expand Up @@ -129,3 +130,11 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str
}
return
}

// Clean the cache of RLIMIT_NOFILE in go runtime
// https://github.com/golang/go/commit/f5eef58e4381259cbd84b3f2074c79607fb5c821#diff-ec665e9789f8cf5cd1828ad7fa9f0ff4ebc1f5b5dd0fc82a296da5c07da7ece6
func CleanRlimitNoFileCache() {
rlimit := syscall.Rlimit{}
syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)

Check failure on line 138 in libcontainer/utils/utils.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `syscall.Getrlimit` is not checked (errcheck)
syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)

Check failure on line 139 in libcontainer/utils/utils.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `syscall.Setrlimit` is not checked (errcheck)
}

0 comments on commit 8e3496c

Please sign in to comment.