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 63ebcf7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libcontainer/setns_init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ func (l *linuxSetnsInit) Init() error {
}
}
}

if err := utils.CleanRlimitNoFileCache(); err != nil {
return err
}

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

if err := utils.CleanRlimitNoFileCache(); err != nil {
return err
}

if err := setupNetwork(l.config); err != nil {
return err
}
Expand Down
11 changes: 11 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,13 @@ 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() error {
rlimit := syscall.Rlimit{}
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil {
return err
}
return syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit)
}

0 comments on commit 63ebcf7

Please sign in to comment.