Skip to content

Commit

Permalink
cgroup: retry file writes on EINTR errors
Browse files Browse the repository at this point in the history
After deploying a version of gvisor built with Go 1.14, we're seeing errors setting up cgroups (we manually run `runsc` via `runsc run`, which creates the cgroup). This turns out to be a known issue with Go: golang/go#38033. Given that the [fix won't be backported](golang/go#39026 (comment)), we should retry writes that may fail with EINTR.

This is also what runc does: opencontainers/runc#2258

FUTURE_COPYBARA_INTEGRATE_REVIEW=#3102 from stripe:andrew/cgroup-eintr 079123b
PiperOrigin-RevId: 320183771
  • Loading branch information
adunham-stripe authored and gvisor-bot committed Jul 8, 2020
1 parent efa2615 commit b5747c5
Showing 1 changed file with 21 additions and 3 deletions.
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)
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

0 comments on commit b5747c5

Please sign in to comment.