Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions libcontainer/cgroups/fs/apply_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,7 @@ func (m *Manager) Destroy() error {
}
m.mu.Lock()
defer m.mu.Unlock()
if err := cgroups.RemovePaths(m.Paths); err != nil {
return err
}
m.Paths = make(map[string]string)
return nil
return cgroups.RemovePaths(m.Paths)
}

func (m *Manager) GetPaths() map[string]string {
Expand Down
12 changes: 7 additions & 5 deletions libcontainer/cgroups/systemd/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,15 @@ func (m *LegacyManager) Destroy() error {
}
m.mu.Lock()
defer m.mu.Unlock()

unitName := getUnitName(m.Cgroups)
if err := stopUnit(unitName); err != nil {
return err

err := stopUnit(unitName)
// 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 err2 := cgroups.RemovePaths(m.Paths); err2 != nil {
return err2
}
m.Paths = make(map[string]string)
return nil
return err
}

func (m *LegacyManager) GetPaths() map[string]string {
Expand Down
1 change: 1 addition & 0 deletions libcontainer/cgroups/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ func RemovePaths(paths map[string]string) (err error) {
}
}
if len(paths) == 0 {
paths = make(map[string]string)
return nil
}
}
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/delete.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ function teardown() {
}

@test "runc delete" {
# run busybox detached
runc run -d --console-socket $CONSOLE_SOCKET test_busybox
runc run -d --console-socket $CONSOLE_SOCKET testbusyboxdelete
[ "$status" -eq 0 ]

# check state
testcontainer test_busybox running
testcontainer testbusyboxdelete running

runc kill test_busybox KILL
runc kill testbusyboxdelete KILL
[ "$status" -eq 0 ]
# wait for busybox to be in the destroyed state
retry 10 1 eval "__runc state test_busybox | grep -q 'stopped'"
retry 10 1 eval "__runc state testbusyboxdelete | grep -q 'stopped'"

# delete test_busybox
runc delete test_busybox
runc delete testbusyboxdelete
[ "$status" -eq 0 ]

runc state test_busybox
runc state testbusyboxdelete
[ "$status" -ne 0 ]

run find /sys/fs/cgroup -wholename '*testbusyboxdelete*' -type d
[ "$status" -eq 0 ]
[ "$output" = "" ] || fail "cgroup not cleaned up correctly: $output"
}

@test "runc delete --force" {
Expand Down