Added a disconnect for sockets with 3+ spurious wakeups.
This commit is contained in:
+15
-3
@@ -179,12 +179,24 @@ fn handle_connection_event(context: Arc<Mutex<Context>>, peers: &mut Peers, regi
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Some(peer) => {
|
Some(peer) => {
|
||||||
let mut stream = peer.get_stream();
|
|
||||||
if event.is_read_closed() {
|
if event.is_read_closed() {
|
||||||
info!("Spurious wakeup for connection {}, ignoring", token.0);
|
debug!("Spurious wakeup for connection {}, ignoring", token.0);
|
||||||
registry.reregister(stream, token, Interest::READABLE).unwrap();
|
if peer.spurious() >= 3 {
|
||||||
|
debug!("Disconnecting socket on 3 spurious wakeups");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
let interest = if let State::Message{..} = peer.get_state() {
|
||||||
|
Interest::WRITABLE
|
||||||
|
} else {
|
||||||
|
Interest::READABLE
|
||||||
|
};
|
||||||
|
let stream = peer.get_stream();
|
||||||
|
registry.reregister(stream, token, interest).unwrap();
|
||||||
|
peer.inc_spurious();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
peer.reset_spurious();
|
||||||
|
let mut stream = peer.get_stream();
|
||||||
read_message(&mut stream)
|
read_message(&mut stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ pub struct Peer {
|
|||||||
public: bool,
|
public: bool,
|
||||||
active: bool,
|
active: bool,
|
||||||
reconnects: u32,
|
reconnects: u32,
|
||||||
|
spurious: u32,
|
||||||
received_block: u64,
|
received_block: u64,
|
||||||
fork: HashMap<u64, Block>
|
fork: HashMap<u64, Block>
|
||||||
}
|
}
|
||||||
@@ -31,6 +32,7 @@ impl Peer {
|
|||||||
public: false,
|
public: false,
|
||||||
active: false,
|
active: false,
|
||||||
reconnects: 0,
|
reconnects: 0,
|
||||||
|
spurious: 0,
|
||||||
received_block: 0,
|
received_block: 0,
|
||||||
fork: HashMap::new()
|
fork: HashMap::new()
|
||||||
}
|
}
|
||||||
@@ -108,6 +110,18 @@ impl Peer {
|
|||||||
self.reconnects = 0;
|
self.reconnects = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn spurious(&self) -> u32 {
|
||||||
|
self.spurious
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn inc_spurious(&mut self) {
|
||||||
|
self.spurious += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reset_spurious(&mut self) {
|
||||||
|
self.spurious = 0;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn disabled(&self) -> bool {
|
pub fn disabled(&self) -> bool {
|
||||||
self.state.disabled() || self.reconnects > 2
|
self.state.disabled() || self.reconnects > 2
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user