mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
f34eb2c003
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>
36 lines
787 B
Go
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)
|
|
}
|
|
}
|
|
}
|