Skip to content

Commit ee24d70

Browse files
authored
Merge pull request #2015 from vasileknik76/hostagent-nofile-limit
hostagent: increase nofile limit
2 parents 355d72a + 3d49d7c commit ee24d70

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

pkg/hostagent/hostagent.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ func (a *HostAgent) Run(ctx context.Context) error {
288288
}
289289
a.emitEvent(ctx, exitingEv)
290290
}()
291+
adjustNofileRlimit()
291292

292293
firstUsernetIndex := limayaml.FirstUsernetIndex(a.y)
293294
if firstUsernetIndex == -1 && *a.y.HostResolver.Enabled {

pkg/hostagent/hostagent_unix.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build !windows
2+
3+
package hostagent
4+
5+
import (
6+
"syscall"
7+
8+
"github.com/sirupsen/logrus"
9+
)
10+
11+
// Default nofile limit is too low on some system.
12+
// For example in the macOS standard terminal is 256.
13+
// It means that there are only ~240 connections available from the host to the vm.
14+
// That function increases the nofile limit for child processes, especially the ssh process
15+
//
16+
// More about limits in go: https://go.dev/issue/46279
17+
func adjustNofileRlimit() {
18+
var limit syscall.Rlimit
19+
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limit); err != nil {
20+
logrus.WithError(err).Debug("failed to get RLIMIT_NOFILE")
21+
} else if limit.Cur != limit.Max {
22+
limit.Cur = limit.Max
23+
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit)
24+
if err != nil {
25+
logrus.WithError(err).Debugf("failed to set RLIMIT_NOFILE (%+v)", limit)
26+
}
27+
}
28+
}

pkg/hostagent/hostagent_windows.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//go:build windows
2+
3+
package hostagent
4+
5+
func adjustNofileRlimit() {}

0 commit comments

Comments
 (0)