Remove the error when stopping the network (#8671)
This commit is contained in:
parent
ee41fa6f30
commit
fe5f5b28d9
@ -475,7 +475,7 @@ impl ChainNotify for EthSync {
|
|||||||
|
|
||||||
fn stop(&self) {
|
fn stop(&self) {
|
||||||
self.eth_handler.snapshot_service.abort_restore();
|
self.eth_handler.snapshot_service.abort_restore();
|
||||||
self.network.stop().unwrap_or_else(|e| warn!("Error stopping network: {:?}", e));
|
self.network.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn broadcast(&self, message_type: ChainMessageType) {
|
fn broadcast(&self, message_type: ChainMessageType) {
|
||||||
@ -833,9 +833,7 @@ impl ManageNetwork for LightSync {
|
|||||||
|
|
||||||
fn stop_network(&self) {
|
fn stop_network(&self) {
|
||||||
self.proto.abort();
|
self.proto.abort();
|
||||||
if let Err(e) = self.network.stop() {
|
self.network.stop();
|
||||||
warn!("Error stopping network: {}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn network_config(&self) -> NetworkConfiguration {
|
fn network_config(&self) -> NetworkConfiguration {
|
||||||
|
@ -162,11 +162,13 @@ impl<Message> IoContext<Message> where Message: Send + Sync + 'static {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Unregister current IO handler.
|
/// Unregister current IO handler.
|
||||||
pub fn unregister_handler(&self) -> Result<(), IoError> {
|
pub fn unregister_handler(&self) {
|
||||||
self.channel.send_io(IoMessage::RemoveHandler {
|
// `send_io` returns an error only if the channel is closed, which means that the
|
||||||
|
// background thread is no longer running. Therefore the handler is no longer active and
|
||||||
|
// can be considered as unregistered.
|
||||||
|
let _ = self.channel.send_io(IoMessage::RemoveHandler {
|
||||||
handler_id: self.handler,
|
handler_id: self.handler,
|
||||||
})?;
|
});
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -396,7 +396,7 @@ impl Host {
|
|||||||
format!("{}", Node::new(info.id().clone(), info.local_endpoint.clone()))
|
format!("{}", Node::new(info.id().clone(), info.local_endpoint.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(&self, io: &IoContext<NetworkIoMessage>) -> Result<(), Error> {
|
pub fn stop(&self, io: &IoContext<NetworkIoMessage>) {
|
||||||
self.stopping.store(true, AtomicOrdering::Release);
|
self.stopping.store(true, AtomicOrdering::Release);
|
||||||
let mut to_kill = Vec::new();
|
let mut to_kill = Vec::new();
|
||||||
for e in self.sessions.read().iter() {
|
for e in self.sessions.read().iter() {
|
||||||
@ -408,8 +408,7 @@ impl Host {
|
|||||||
trace!(target: "network", "Disconnecting on shutdown: {}", p);
|
trace!(target: "network", "Disconnecting on shutdown: {}", p);
|
||||||
self.kill_connection(p, io, true);
|
self.kill_connection(p, io, true);
|
||||||
}
|
}
|
||||||
io.unregister_handler()?;
|
io.unregister_handler();
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all connected peers.
|
/// Get all connected peers.
|
||||||
|
@ -125,15 +125,14 @@ impl NetworkService {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Stop network IO
|
/// Stop network IO.
|
||||||
pub fn stop(&self) -> Result<(), Error> {
|
pub fn stop(&self) {
|
||||||
let mut host = self.host.write();
|
let mut host = self.host.write();
|
||||||
if let Some(ref host) = *host {
|
if let Some(ref host) = *host {
|
||||||
let io = IoContext::new(self.io_service.channel(), 0); //TODO: take token id from host
|
let io = IoContext::new(self.io_service.channel(), 0); //TODO: take token id from host
|
||||||
host.stop(&io)?;
|
host.stop(&io);
|
||||||
}
|
}
|
||||||
*host = None;
|
*host = None;
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a list of all connected peers by id.
|
/// Get a list of all connected peers by id.
|
||||||
|
@ -112,7 +112,7 @@ fn net_start_stop() {
|
|||||||
let config = NetworkConfiguration::new_local();
|
let config = NetworkConfiguration::new_local();
|
||||||
let service = NetworkService::new(config, None).unwrap();
|
let service = NetworkService::new(config, None).unwrap();
|
||||||
service.start().unwrap();
|
service.start().unwrap();
|
||||||
service.stop().unwrap();
|
service.stop();
|
||||||
service.start().unwrap();
|
service.start().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user