Cleaner shutdown process (#992)

* Cleaner shutdown process

* Finish

* Fix Yamux panic

* Remove irrelevant tests

* Update core/src/nodes/handled_node_tasks.rs

Co-Authored-By: tomaka <pierre.krieger1708@gmail.com>

* Fix yamux error handling

* Update yamux
This commit is contained in:
Pierre Krieger
2019-03-11 17:19:50 +01:00
committed by GitHub
parent cb93c822f1
commit 8059a693a3
32 changed files with 434 additions and 1555 deletions

View File

@ -42,10 +42,6 @@ where
/// Configuration for the Kademlia protocol.
config: KademliaProtocolConfig,
/// If true, we are trying to shut down the existing Kademlia substream and should refuse any
/// incoming connection.
shutting_down: bool,
/// If false, we always refuse incoming Kademlia substreams.
allow_listening: bool,
@ -321,7 +317,6 @@ where
fn with_allow_listening(allow_listening: bool) -> Self {
KademliaHandler {
config: Default::default(),
shutting_down: false,
allow_listening,
next_connec_unique_id: UniqueConnecId(0),
substreams: Vec::new(),
@ -368,10 +363,6 @@ where
protocol: <Self::OutboundProtocol as OutboundUpgrade<TSubstream>>::Output,
(msg, user_data): Self::OutboundOpenInfo,
) {
if self.shutting_down {
return;
}
self.substreams
.push(SubstreamState::OutPendingSend(protocol, msg, user_data));
}
@ -387,10 +378,6 @@ where
EitherOutput::Second(p) => void::unreachable(p),
};
if self.shutting_down {
return;
}
debug_assert!(self.allow_listening);
let connec_unique_id = self.next_connec_unique_id;
self.next_connec_unique_id.0 += 1;
@ -476,9 +463,6 @@ where
}
}
#[inline]
fn inject_inbound_closed(&mut self) {}
#[inline]
fn inject_dial_upgrade_error(
&mut self,
@ -498,33 +482,12 @@ where
self.keep_alive
}
#[inline]
fn shutdown(&mut self) {
self.shutting_down = true;
}
fn poll(
&mut self,
) -> Poll<
ProtocolsHandlerEvent<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::OutEvent>,
io::Error,
> {
// Special case if shutting down.
if self.shutting_down {
for n in (0..self.substreams.len()).rev() {
match self.substreams.swap_remove(n).try_close() {
AsyncSink::Ready => (),
AsyncSink::NotReady(stream) => self.substreams.push(stream),
}
}
if self.substreams.is_empty() {
return Ok(Async::Ready(ProtocolsHandlerEvent::Shutdown));
} else {
return Ok(Async::NotReady);
}
}
// We remove each element from `substreams` one by one and add them back.
for n in (0..self.substreams.len()).rev() {
let mut substream = self.substreams.swap_remove(n);