cgroupfs: Fix test race with task exit.

The PID controller isn't uncharged synchronously with task exit. The
test checks the PID is released after thread join, which races with
the task being reaped.

PiperOrigin-RevId: 444960688
This commit is contained in:
Rahat Mahmood
2022-04-27 14:06:51 -07:00
committed by gVisor bot
parent 7124367b82
commit 5afe17a15d
3 changed files with 15 additions and 1 deletions
+2 -1
View File
@@ -1214,7 +1214,8 @@ TEST(PIDsCgroup, LimitEnforced) {
IsPosixErrorOkAndHolds(baseline + 1));
// Exit the first thread and try create a thread again, which should succeed.
t1.Join();
ASSERT_NO_ERRNO(child.PollControlFileForChangeAfter(
"pids.current", absl::Seconds(30), [&t1]() { t1.Join(); }));
ASSERT_THAT(child.ReadIntegerControlFile("pids.current"),
IsPosixErrorOkAndHolds(baseline));
NoopThreads t2(1);
+8
View File
@@ -87,6 +87,12 @@ PosixErrorOr<absl::flat_hash_set<pid_t>> Cgroup::Tasks() const {
PosixError Cgroup::PollControlFileForChange(absl::string_view name,
absl::Duration timeout) const {
return PollControlFileForChangeAfter(name, timeout, []() {});
}
PosixError Cgroup::PollControlFileForChangeAfter(
absl::string_view name, absl::Duration timeout,
std::function<void()> body) const {
const absl::Duration poll_interval = absl::Milliseconds(10);
const absl::Time deadline = absl::Now() + timeout;
const std::string alias_path = absl::StrFormat("[cg#%d]/%s", id_, name);
@@ -94,6 +100,8 @@ PosixError Cgroup::PollControlFileForChange(absl::string_view name,
ASSIGN_OR_RETURN_ERRNO(const int64_t initial_value,
ReadIntegerControlFile(name));
body();
while (true) {
ASSIGN_OR_RETURN_ERRNO(const int64_t current_value,
ReadIntegerControlFile(name));
+5
View File
@@ -78,6 +78,11 @@ class Cgroup {
PosixError PollControlFileForChange(absl::string_view name,
absl::Duration timeout) const;
// Waits for a control file's value to change after calling body.
PosixError PollControlFileForChangeAfter(absl::string_view name,
absl::Duration timeout,
std::function<void()> body) const;
// Returns the thread ids of the leaders of thread groups managed by this
// cgroup.
PosixErrorOr<absl::flat_hash_set<pid_t>> Procs() const;