Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Fixed network service dispose #1339

Merged
merged 1 commit into from
Jun 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions parity/io_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

use std::sync::Arc;
use std::sync::{Arc, Weak};
use ethcore::client::Client;
use ethcore::service::{NetSyncMessage, SyncMessage};
use ethsync::EthSync;
Expand All @@ -30,7 +30,7 @@ pub struct ClientIoHandler {
pub sync: Arc<EthSync>,
pub accounts: Arc<AccountProvider>,
pub info: Informant,
pub network: Arc<NetworkService<SyncMessage>>,
pub network: Weak<NetworkService<SyncMessage>>,
}

impl IoHandler<NetSyncMessage> for ClientIoHandler {
Expand All @@ -49,12 +49,16 @@ impl IoHandler<NetSyncMessage> for ClientIoHandler {
match *message {
NetworkIoMessage::User(SyncMessage::StartNetwork) => {
info!("Starting network");
self.network.start().unwrap_or_else(|e| warn!("Error starting network: {:?}", e));
EthSync::register(&*self.network, self.sync.clone()).unwrap_or_else(|e| warn!("Error registering eth protocol handler: {}", e));
if let Some(network) = self.network.upgrade() {
network.start().unwrap_or_else(|e| warn!("Error starting network: {:?}", e));
EthSync::register(&*network, self.sync.clone()).unwrap_or_else(|e| warn!("Error registering eth protocol handler: {}", e));
}
},
NetworkIoMessage::User(SyncMessage::StopNetwork) => {
info!("Stopping network");
self.network.stop().unwrap_or_else(|e| warn!("Error stopping network: {:?}", e));
if let Some(network) = self.network.upgrade() {
network.stop().unwrap_or_else(|e| warn!("Error stopping network: {:?}", e));
}
},
_ => {/* Ignore other messages */},
}
Expand Down
2 changes: 1 addition & 1 deletion parity/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
info: Informant::new(conf.have_color()),
sync: sync.clone(),
accounts: account_service.clone(),
network: service.network(),
network: Arc::downgrade(&service.network()),
});
service.register_io_handler(io_handler).expect("Error registering IO handler");

Expand Down