Skip to content

cgroups: reapp child processes before destroying cgroup #13135

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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: 6 additions & 0 deletions src/libutil/linux/cgroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cmath>
#include <regex>
#include <unordered_set>
#include <sys/wait.h>
#include <thread>

#include <dirent.h>
Expand Down Expand Up @@ -101,6 +102,11 @@ static CgroupStats destroyCgroup(const std::filesystem::path & cgroup, bool retu
// FIXME: pid wraparound
if (kill(pid, SIGKILL) == -1 && errno != ESRCH)
throw SysError("killing member %d of cgroup '%s'", pid, cgroup);

while (waitpid(pid, nullptr, 0) == -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it matters, but I think this only works for processes that are direct children of the current process? For others it will return ECHILD according to the manpage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also seems like it doesn't work correctly because there some other code that uses waitpid and crashes if there is no wait result.

if (errno == ECHILD) break; // Process already reaped
if (errno != EINTR) throw SysError("waiting for pid %d", pid);
}
}

auto sleep = std::chrono::milliseconds((int) std::pow(2.0, std::min(round, 10)));
Expand Down
Loading