From e59be804b16d15ddfb009c9793f87aeb7d49c7a4 Mon Sep 17 00:00:00 2001 From: "jingxu.zm" Date: Fri, 24 May 2024 10:41:50 +0800 Subject: [PATCH] monitor_notify_by_pid may be blocked by send msg to channel because bounded channel is full(but monitor lock has not be freed), on the other hand,monitor_unsubscribe may block because monitor lock is holded by the monitor_notify_by_pid --- crates/shim/src/asynchronous/monitor.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/shim/src/asynchronous/monitor.rs b/crates/shim/src/asynchronous/monitor.rs index b29545fe..41ba6034 100644 --- a/crates/shim/src/asynchronous/monitor.rs +++ b/crates/shim/src/asynchronous/monitor.rs @@ -19,7 +19,7 @@ use std::collections::HashMap; use lazy_static::lazy_static; use log::error; use tokio::sync::{ - mpsc::{channel, Receiver, Sender}, + mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender}, Mutex, }; @@ -68,17 +68,17 @@ pub struct Monitor { pub(crate) struct Subscriber { pub(crate) topic: Topic, - pub(crate) tx: Sender, + pub(crate) tx: UnboundedSender, } pub struct Subscription { pub id: i64, - pub rx: Receiver, + pub rx: UnboundedReceiver, } impl Monitor { pub fn subscribe(&mut self, topic: Topic) -> Result { - let (tx, rx) = channel::(128); + let (tx, rx) = unbounded_channel::(); let id = self.seq_id; self.seq_id += 1; let subscriber = Subscriber { @@ -120,7 +120,6 @@ impl Monitor { subject: subject.clone(), exit_code, }) - .await .map_err(other_error!(e, "failed to send exit code")); results.push(res); }