diff --git a/libcontainer/cgroups/systemd/common.go b/libcontainer/cgroups/systemd/common.go index 91c314e09..563afc9f3 100644 --- a/libcontainer/cgroups/systemd/common.go +++ b/libcontainer/cgroups/systemd/common.go @@ -355,6 +355,9 @@ func stopUnit(cm *dbusConnManager, unitName string) error { return err }) if err == nil { + timeout := time.NewTimer(30 * time.Second) + defer timeout.Stop() + select { case s := <-statusChan: close(statusChan) @@ -362,8 +365,8 @@ func stopUnit(cm *dbusConnManager, unitName string) error { if s != "done" { logrus.Warnf("error removing unit `%s`: got `%s`. Continuing...", unitName, s) } - case <-time.After(time.Second): - logrus.Warnf("Timed out while waiting for StopUnit(%s) completion signal from dbus. Continuing...", unitName) + case <-timeout.C: + return errors.New("Timed out while waiting for systemd to remove " + unitName) } } return nil diff --git a/libcontainer/cgroups/systemd/v1.go b/libcontainer/cgroups/systemd/v1.go index 41de6e8b7..b6a70e024 100644 --- a/libcontainer/cgroups/systemd/v1.go +++ b/libcontainer/cgroups/systemd/v1.go @@ -207,9 +207,10 @@ func (m *legacyManager) Destroy() error { stopErr := stopUnit(m.dbus, getUnitName(m.cgroups)) - // Both on success and on error, cleanup all the cgroups we are aware of. - // Some of them were created directly by Apply() and are not managed by systemd. - if err := cgroups.RemovePaths(m.paths); err != nil { + // Both on success and on error, cleanup all the cgroups + // we are aware of, as some of them were created directly + // by Apply() and are not managed by systemd. + if err := cgroups.RemovePaths(m.paths); err != nil && stopErr == nil { return err }