Skip to content

Commit 079123b

Browse files
cgroup: retry file writes on EINTR errors
1 parent e8f1a5c commit 079123b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

runsc/cgroup/cgroup.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,17 @@ func setOptionalValueUint16(path, name string, val *uint16) error {
9292

9393
func setValue(path, name, data string) error {
9494
fullpath := filepath.Join(path, name)
95-
return ioutil.WriteFile(fullpath, []byte(data), 0700)
95+
96+
// Retry writes on EINTR; see:
97+
// https://github.com/golang/go/issues/38033
98+
for {
99+
err := ioutil.WriteFile(fullpath, []byte(data), 0700)
100+
if err == nil {
101+
return nil
102+
} else if !errors.Is(err, syscall.EINTR) {
103+
return err
104+
}
105+
}
96106
}
97107

98108
func getValue(path, name string) (string, error) {
@@ -132,8 +142,16 @@ func fillFromAncestor(path string) (string, error) {
132142
if err != nil {
133143
return "", err
134144
}
135-
if err := ioutil.WriteFile(path, []byte(val), 0700); err != nil {
136-
return "", err
145+
146+
// Retry writes on EINTR; see:
147+
// https://github.com/golang/go/issues/38033
148+
for {
149+
err := ioutil.WriteFile(path, []byte(val), 0700)
150+
if err == nil {
151+
break
152+
} else if !errors.Is(err, syscall.EINTR) {
153+
return "", err
154+
}
137155
}
138156
return val, nil
139157
}

0 commit comments

Comments
 (0)