Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cgroup: retry file writes on EINTR errors #3102

Merged
merged 1 commit into from
Jul 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions runsc/cgroup/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,17 @@ func setOptionalValueUint16(path, name string, val *uint16) error {

func setValue(path, name, data string) error {
fullpath := filepath.Join(path, name)
return ioutil.WriteFile(fullpath, []byte(data), 0700)

// Retry writes on EINTR; see:
// https://github.com/golang/go/issues/38033
for {
err := ioutil.WriteFile(fullpath, []byte(data), 0700)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

if errors.Is(err, syscall.EINTR) {
continue
}
return err

if err == nil {
return nil
} else if !errors.Is(err, syscall.EINTR) {
return err
}
}
}

func getValue(path, name string) (string, error) {
Expand Down Expand Up @@ -132,8 +142,16 @@ func fillFromAncestor(path string) (string, error) {
if err != nil {
return "", err
}
if err := ioutil.WriteFile(path, []byte(val), 0700); err != nil {
return "", err

// Retry writes on EINTR; see:
// https://github.com/golang/go/issues/38033
for {
err := ioutil.WriteFile(path, []byte(val), 0700)
if err == nil {
break
} else if !errors.Is(err, syscall.EINTR) {
return "", err
}
}
return val, nil
}
Expand Down