Uninstall() should not fail if a cgroup directory doesn't exist

It can be occurred if two controllers are mounted together or if Uninstall() is called on a error path.

PiperOrigin-RevId: 218723886
Change-Id: I69d7a3c0685a7da38527ea8b7b301dbe96268285
This commit is contained in:
Andrei Vagin
2018-10-25 11:46:35 -07:00
committed by Shentubot
parent a5fe397cf8
commit 479cd52a60
2 changed files with 16 additions and 1 deletions
+5 -1
View File
@@ -229,7 +229,11 @@ func (c *Cgroup) Uninstall() error {
defer cancel()
b := backoff.WithContext(backoff.NewConstantBackOff(100*time.Millisecond), ctx)
if err := backoff.Retry(func() error {
return syscall.Rmdir(path)
err := syscall.Rmdir(path)
if os.IsNotExist(err) {
return nil
}
return err
}, b); err != nil {
return fmt.Errorf("error removing cgroup path %q: %v", path, err)
}
+11
View File
@@ -18,6 +18,17 @@ import (
"testing"
)
func TestUninstallEnoent(t *testing.T) {
c := Cgroup{
// set a non-existent name
Name: "runsc-test-uninstall-656e6f656e740a",
Own: true,
}
if err := c.Uninstall(); err != nil {
t.Errorf("Uninstall() failed: %v", err)
}
}
func TestCountCpuset(t *testing.T) {
for _, tc := range []struct {
str string