Files
runc/libcontainer/cgroups/fscommon/fscommon_test.go
T
Danail Branekov f34eb2c003 Retry writing to cgroup files on EINTR error
Golang 1.14 introduces asynchronous preemption which results into
applications getting frequent EINTR (syscall interrupted) errors when
invoking slow syscalls, e.g. when writing to cgroup files.

As writing to cgroups is idempotent, it is safe to retry writing to the
file whenever the write syscall is interrupted.

Signed-off-by: Mario Nitchev <marionitchev@gmail.com>
2020-03-18 13:00:05 +02:00

36 lines
787 B
Go

// +build linux
package fscommon
import (
"fmt"
"os"
"path/filepath"
"strconv"
"testing"
"time"
"github.com/opencontainers/runc/libcontainer/cgroups"
)
func TestWriteCgroupFileHandlesInterrupt(t *testing.T) {
memoryCgroupMount, err := cgroups.FindCgroupMountpoint("", "memory")
if err != nil {
t.Fatal(err)
}
cgroupName := fmt.Sprintf("test-eint-%d", time.Now().Nanosecond())
cgroupPath := filepath.Join(memoryCgroupMount, cgroupName)
if err := os.MkdirAll(cgroupPath, 0755); err != nil {
t.Fatal(err)
}
defer os.RemoveAll(cgroupPath)
for i := 0; i < 100000; i++ {
limit := 1024*1024 + i
if err := WriteFile(cgroupPath, "memory.limit_in_bytes", strconv.Itoa(limit)); err != nil {
t.Fatalf("Failed to write %d on attempt %d: %+v", limit, i, err)
}
}
}