Skip to content

Commit

Permalink
fix(nsjail): improve memory reading when using nsjail
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenfiszel committed Oct 17, 2024
1 parent 45bf59b commit b7ad19b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/windmill-worker/src/bun_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ try {{
mem_peak,
canceled_by,
child,
false,
!*DISABLE_NSJAIL,
worker_name,
&job.workspace_id,
"bun run",
Expand Down
27 changes: 24 additions & 3 deletions backend/windmill-worker/src/handle_child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,30 @@ async fn get_mem_peak(pid: Option<u32>, nsjail: bool) -> i32 {
return -1;
}
let pid = if nsjail {
// This is a bit hacky, but the process id of the nsjail process is the pid of nsjail + 1.
// Ideally, we would get the number from fork() itself. This works in MOST cases.
pid.unwrap() + 1
// Read /proc/<nsjail_pid>/task/<nsjail_pid>/children and extract pid
let nsjail_pid = pid.unwrap();
let children_path = format!("/proc/{}/task/{}/children", nsjail_pid, nsjail_pid);
if let Ok(mut file) = File::open(children_path).await {
let mut contents = String::new();
if tokio::io::AsyncReadExt::read_to_string(&mut file, &mut contents)
.await
.is_ok()
{
if let Some(child_pid) = contents.split_whitespace().next() {
if let Ok(child_pid) = child_pid.parse::<u32>() {
child_pid
} else {
return -1;
}
} else {
return -1;
}
} else {
return -1;
}
} else {
return -1;
}
} else {
pid.unwrap()
};
Expand Down
2 changes: 1 addition & 1 deletion backend/windmill-worker/src/php_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ try {{
mem_peak,
canceled_by,
child,
false,
!*DISABLE_NSJAIL,
worker_name,
&job.workspace_id,
"php run",
Expand Down

0 comments on commit b7ad19b

Please sign in to comment.