-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
cryptpilot/src/provider/mod.rs
Lines 226 to 229 in 8deab3e
| .pre_exec(move || { | |
| cg.add_task(CgroupPid::from(std::process::id() as u64)) | |
| .map_err(Error::other) | |
| }) |
This snippet is invalid in multi-threaded programs, which AFAIK cryptpilot is. The problem is due to two factors:
Error::otheralways allocates (see Document Error::{new,other} as to be avoided in pre_exec rust-lang/rust#148971).Cgroup::add_taskallocates internally, since it needs to write to a file and do other stuff.
Allocating in pre_exec is bad because forking while the allocator lock is held by another thread can cause deadlocks, since there's no one left to unlock the mutex. I do not believe this is UB per se, but it seems less than ideal still. glibc and other modern libc offer protections against that, as far as I'm aware, but this isn't POSIX-compliant and should preferably be avoided.
Your options are:
- Since this function is only run in tests, you could probably update
test_volume_baseto use a single-threaded runtime, which might resolve the problem. I'm not sure if this works, but it's worth trying. - A generally correct solution would be to make a thread in the parent process responsible for adding the process to the cgroup, and communicate with that thread from the child process via IPC (say, pipes).
Metadata
Metadata
Assignees
Labels
No labels