Skip to content

Commit

Permalink
Merge pull request #94 from python-discord/recursive-remove-cgroups
Browse files Browse the repository at this point in the history
Remove all child cgroups before removing parents
  • Loading branch information
Akarys42 committed Feb 26, 2021
2 parents af704c1 + 06173ee commit 59a1bf4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions snekbox/nsjail.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ def python3(self, code: str, *args) -> CompletedProcess:

log.info(f"nsjail return code: {returncode}")

# If we hit a cgroup limit then there is a chance the nsjail cgroups did not
# get removed. If we don't remove them then when we try remove the parents
# we will get a "Device or resource busy" error.

children = []

children.extend(Path(self.config.cgroup_mem_mount, cgroup).glob("NSJAIL.*"))
children.extend(Path(self.config.cgroup_pids_mount, cgroup).glob("NSJAIL.*"))

for child in children:
child.rmdir()

# Remove the dynamically created cgroups once we're done
Path(self.config.cgroup_mem_mount, cgroup).rmdir()
Path(self.config.cgroup_pids_mount, cgroup).rmdir()
Expand Down

0 comments on commit 59a1bf4

Please sign in to comment.