mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
committed by
gVisor bot
parent
7124367b82
commit
5afe17a15d
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user