Use a weak reference from channel reactor to channel.
This commit is contained in:
parent
ffe605aa52
commit
4646a4546e
|
@ -19,7 +19,7 @@ use futures::select_biased;
|
||||||
use futures::sink::SinkExt;
|
use futures::sink::SinkExt;
|
||||||
use futures::stream::{self, SplitStream, StreamExt};
|
use futures::stream::{self, SplitStream, StreamExt};
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Weak};
|
||||||
|
|
||||||
use log::trace;
|
use log::trace;
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ struct ReactorCore {
|
||||||
circs: Arc<Mutex<CircMap>>,
|
circs: Arc<Mutex<CircMap>>,
|
||||||
|
|
||||||
/// Channel pointer -- used to send DESTROY cells.
|
/// Channel pointer -- used to send DESTROY cells.
|
||||||
channel: Arc<Mutex<super::ChannelImpl>>,
|
channel: Weak<Mutex<super::ChannelImpl>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Reactor<T>
|
impl<T> Reactor<T>
|
||||||
|
@ -99,7 +99,7 @@ where
|
||||||
input: SplitStream<CellFrame<T>>,
|
input: SplitStream<CellFrame<T>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let core = ReactorCore {
|
let core = ReactorCore {
|
||||||
channel,
|
channel: Arc::downgrade(&channel),
|
||||||
circs: circmap,
|
circs: circmap,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -292,8 +292,10 @@ impl ReactorCore {
|
||||||
// TODO: use a constant for DESTROY_REASON_NONE.
|
// TODO: use a constant for DESTROY_REASON_NONE.
|
||||||
let destroy = Destroy::new(0).into();
|
let destroy = Destroy::new(0).into();
|
||||||
let cell = ChanCell::new(id, destroy);
|
let cell = ChanCell::new(id, destroy);
|
||||||
let mut chan = self.channel.lock().await;
|
if let Some(chan) = self.channel.upgrade() {
|
||||||
chan.send_cell(cell).await?;
|
let mut chan = chan.lock().await;
|
||||||
|
chan.send_cell(cell).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue