-
Notifications
You must be signed in to change notification settings - Fork 240
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
Check that cgroup is empty before deleting #228
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -337,6 +337,14 @@ func (c *Manager) AddProc(pid uint64) error { | |
} | ||
|
||
func (c *Manager) Delete() error { | ||
// kernel prevents cgroups with running process from being removed, check the tree is empty | ||
processes, err := c.Procs(true) | ||
if err != nil { | ||
return err | ||
} | ||
if len(processes) > 0 { | ||
return fmt.Errorf("cgroups: unable to remove path %q: still contains running processes", c.path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to have a similar message on cgroup.go? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The v1 Delete just accumulates a list of subsystems that couldn't be removed and doesn't report the error. I could make the append more like:
be a solution? Then the resulting error would be akin to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good to me! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apologies for not getting back to this sooner, I added the "contains running process" reason to the errors list in cgroup.go |
||
} | ||
return remove(c.path) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this
continue
necessary? I don't see how it changes loop flow since this is the end of thefor
and will naturally continue through the end of the range of subsystems.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not strictly necessary, no. I added it to because from my interpretation of the structure of the code here, it's sort of like a switch case and only one branch should be valid, so if there was ever a third case (very unlikely since cgroup v1 is now legacy code), this would be correct for that situation.
Looking at it a bit more, I think it would be better if those two
if
blocks were restructured to better represent that intent that only one interface is expected to be matched. What do you think of something more like this, would that be more readable?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continue
looks okay to me to be honest.switch
could work, but it couldn't haveif len(procs) > 0 {
case which is anothercontinue
case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed with @estesp offline that this is not a blocker.