Skip to content

Commit

Permalink
fix exec hang when tx channel is full
Browse files Browse the repository at this point in the history
  • Loading branch information
ningmingxiao committed Sep 29, 2024
1 parent 217f0ee commit 4a575f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
5 changes: 4 additions & 1 deletion crates/runc-shim/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ async fn process_exits(
if let Subject::Pid(pid) = e.subject {
debug!("receive exit event: {}", &e);
let exit_code = e.exit_code;
let containers = containers.clone();
let tx = tx.clone();
tokio::spawn(async move {
for (_k, cont) in containers.lock().await.iter_mut() {
let bundle = cont.bundle.to_string();
// pid belongs to container init process
Expand Down Expand Up @@ -204,7 +207,7 @@ async fn process_exits(
break;
}
}
}
}});
}
}
monitor_unsubscribe(s.id).await.unwrap_or_default();
Expand Down
10 changes: 5 additions & 5 deletions crates/shim/src/asynchronous/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::collections::HashMap;
use lazy_static::lazy_static;
use log::error;
use tokio::sync::{
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
mpsc::{channel, Receiver, Sender},
Mutex,
};

Expand Down Expand Up @@ -68,17 +68,17 @@ pub struct Monitor {

pub(crate) struct Subscriber {
pub(crate) topic: Topic,
pub(crate) tx: UnboundedSender<ExitEvent>,
pub(crate) tx: Sender<ExitEvent>,
}

pub struct Subscription {
pub id: i64,
pub rx: UnboundedReceiver<ExitEvent>,
pub rx: Receiver<ExitEvent>,
}

impl Monitor {
pub fn subscribe(&mut self, topic: Topic) -> Result<Subscription> {
let (tx, rx) = unbounded_channel::<ExitEvent>();
let (tx, rx) = channel::<ExitEvent>(128);
let id = self.seq_id;
self.seq_id += 1;
let subscriber = Subscriber {
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Monitor {
.send(ExitEvent {
subject: subject.clone(),
exit_code,
})
}).await
.map_err(other_error!(e, "failed to send exit code"));
results.push(res);
}
Expand Down

0 comments on commit 4a575f1

Please sign in to comment.