Refactor spots to make use of sys.IgnoringEintr

This makes use of pkg/sys's IgnoringEintr function
to clean up some of the redundant eintr loops we
had laying around.

Signed-off-by: Danny Canter <danny@dcantah.dev>
This commit is contained in:
Danny Canter
2024-04-10 04:15:55 -07:00
parent 3ea69db8e9
commit b50e9eae43
4 changed files with 39 additions and 77 deletions

View File

@@ -25,6 +25,7 @@ import (
"golang.org/x/sys/unix"
cgroups "github.com/containerd/cgroups/v3/cgroup1"
"github.com/containerd/containerd/v2/pkg/sys"
"github.com/containerd/log"
metrics "github.com/docker/go-metrics"
"github.com/prometheus/client_golang/prometheus"
@@ -110,16 +111,20 @@ func (o *oomCollector) Close() error {
}
func (o *oomCollector) start() {
var events [128]unix.EpollEvent
var (
n int
err error
events [128]unix.EpollEvent
)
for {
n, err := unix.EpollWait(o.fd, events[:], -1)
if err != nil {
if err == unix.EINTR {
continue
}
if err := sys.IgnoringEINTR(func() error {
n, err = unix.EpollWait(o.fd, events[:], -1)
return err
}); err != nil {
log.L.WithError(err).Error("cgroups: epoll wait failed, OOM notifications disabled")
return
}
for i := 0; i < n; i++ {
o.process(uintptr(events[i].Fd))
}