mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-21 03:21:08 +03:00
Fix recently introduced peer deadlock (#1941)
This commit is contained in:
parent
8742c334dd
commit
d2088ff48c
1 changed files with 9 additions and 17 deletions
|
@ -351,24 +351,12 @@ impl Peer {
|
||||||
|
|
||||||
/// Stops the peer, closing its connection
|
/// Stops the peer, closing its connection
|
||||||
pub fn stop(&self) {
|
pub fn stop(&self) {
|
||||||
let _ = self
|
stop_with_connection(&self.connection.as_ref().unwrap().lock());
|
||||||
.connection
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.lock()
|
|
||||||
.close_channel
|
|
||||||
.send(());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_connection(&self) -> bool {
|
fn check_connection(&self) -> bool {
|
||||||
match self
|
let connection = self.connection.as_ref().unwrap().lock();
|
||||||
.connection
|
match connection.error_channel.try_recv() {
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.lock()
|
|
||||||
.error_channel
|
|
||||||
.try_recv()
|
|
||||||
{
|
|
||||||
Ok(Error::Serialization(e)) => {
|
Ok(Error::Serialization(e)) => {
|
||||||
let need_stop = {
|
let need_stop = {
|
||||||
let mut state = self.state.write();
|
let mut state = self.state.write();
|
||||||
|
@ -384,7 +372,7 @@ impl Peer {
|
||||||
"Client {} corrupted, will disconnect ({:?}).",
|
"Client {} corrupted, will disconnect ({:?}).",
|
||||||
self.info.addr, e
|
self.info.addr, e
|
||||||
);
|
);
|
||||||
self.stop();
|
stop_with_connection(&connection);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -400,7 +388,7 @@ impl Peer {
|
||||||
};
|
};
|
||||||
if need_stop {
|
if need_stop {
|
||||||
debug!("Client {} connection lost: {:?}", self.info.addr, e);
|
debug!("Client {} connection lost: {:?}", self.info.addr, e);
|
||||||
self.stop();
|
stop_with_connection(&connection);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -412,6 +400,10 @@ impl Peer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn stop_with_connection(connection: &conn::Tracker) {
|
||||||
|
let _ = connection.close_channel.send(());
|
||||||
|
}
|
||||||
|
|
||||||
/// Adapter implementation that forwards everything to an underlying adapter
|
/// Adapter implementation that forwards everything to an underlying adapter
|
||||||
/// but keeps track of the block and transaction hashes that were received.
|
/// but keeps track of the block and transaction hashes that were received.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
Loading…
Reference in a new issue