Skip to content

Commit 4a575f1

Browse files
committed
fix exec hang when tx channel is full
1 parent 217f0ee commit 4a575f1

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

crates/runc-shim/src/service.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ async fn process_exits(
159159
if let Subject::Pid(pid) = e.subject {
160160
debug!("receive exit event: {}", &e);
161161
let exit_code = e.exit_code;
162+
let containers = containers.clone();
163+
let tx = tx.clone();
164+
tokio::spawn(async move {
162165
for (_k, cont) in containers.lock().await.iter_mut() {
163166
let bundle = cont.bundle.to_string();
164167
// pid belongs to container init process
@@ -204,7 +207,7 @@ async fn process_exits(
204207
break;
205208
}
206209
}
207-
}
210+
}});
208211
}
209212
}
210213
monitor_unsubscribe(s.id).await.unwrap_or_default();

crates/shim/src/asynchronous/monitor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::collections::HashMap;
1919
use lazy_static::lazy_static;
2020
use log::error;
2121
use tokio::sync::{
22-
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
22+
mpsc::{channel, Receiver, Sender},
2323
Mutex,
2424
};
2525

@@ -68,17 +68,17 @@ pub struct Monitor {
6868

6969
pub(crate) struct Subscriber {
7070
pub(crate) topic: Topic,
71-
pub(crate) tx: UnboundedSender<ExitEvent>,
71+
pub(crate) tx: Sender<ExitEvent>,
7272
}
7373

7474
pub struct Subscription {
7575
pub id: i64,
76-
pub rx: UnboundedReceiver<ExitEvent>,
76+
pub rx: Receiver<ExitEvent>,
7777
}
7878

7979
impl Monitor {
8080
pub fn subscribe(&mut self, topic: Topic) -> Result<Subscription> {
81-
let (tx, rx) = unbounded_channel::<ExitEvent>();
81+
let (tx, rx) = channel::<ExitEvent>(128);
8282
let id = self.seq_id;
8383
self.seq_id += 1;
8484
let subscriber = Subscriber {
@@ -116,7 +116,7 @@ impl Monitor {
116116
.send(ExitEvent {
117117
subject: subject.clone(),
118118
exit_code,
119-
})
119+
}).await
120120
.map_err(other_error!(e, "failed to send exit code"));
121121
results.push(res);
122122
}

0 commit comments

Comments
 (0)