Skip to content

Commit 683f674

Browse files
committed
fix(pegboard): fix container runner orphaning
1 parent 1336a33 commit 683f674

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

packages/edge/infra/client/container-runner/src/container.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{
22
fs,
33
io::{BufRead, BufReader},
4+
os::unix::process::CommandExt,
45
path::Path,
56
process::{Command, Stdio},
67
sync::mpsc,
@@ -9,6 +10,7 @@ use std::{
910
};
1011

1112
use anyhow::*;
13+
use nix::sys::{prctl::set_pdeathsig, signal::Signal};
1214
use signal_hook::{consts::signal::SIGTERM, iterator::Signals};
1315

1416
use crate::{log_shipper, throttle, MAX_LINE_BYTES};
@@ -68,15 +70,25 @@ pub fn run(
6870
actor_id,
6971
fs_path.display()
7072
);
71-
let mut runc_child = Command::new("runc")
73+
74+
let mut runc_child = Command::new("runc");
75+
let runc_child = runc_child
7276
.arg("run")
7377
.arg(&actor_id)
7478
.arg("-b")
7579
.arg(fs_path)
7680
.stdout(Stdio::piped())
77-
.stderr(Stdio::piped())
78-
.spawn()
79-
.expect("failed to spawn runc");
81+
.stderr(Stdio::piped());
82+
83+
let runc_child = unsafe {
84+
runc_child.pre_exec(|| {
85+
// Set the child to receive SIGKILL when parent dies
86+
set_pdeathsig(Signal::SIGKILL)
87+
.map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err))
88+
})
89+
};
90+
91+
let mut runc_child = runc_child.spawn().expect("failed to spawn runc");
8092
let runc_stdout = BufReader::new(runc_child.stdout.take().unwrap());
8193
let runc_stderr = BufReader::new(runc_child.stderr.take().unwrap());
8294

packages/edge/infra/client/manager/src/actor/setup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ impl Actor {
719719
match Command::new("runc")
720720
.arg("delete")
721721
.arg("--force")
722-
.arg(self.actor_id.to_string())
722+
.arg(format!("{}-{}", self.actor_id, self.generation))
723723
.output()
724724
.await
725725
{

0 commit comments

Comments
 (0)