From 58d55715e064faaf00f6ed09ed2515845cd3e958 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Fri, 18 May 2018 18:41:47 +0200 Subject: [PATCH 1/3] Shutdown the Snapshot Service when shutting down the runner --- ethcore/service/src/service.rs | 7 ++++++- ethcore/src/snapshot/service.rs | 4 ++++ ethcore/src/snapshot/traits.rs | 3 +++ parity/run.rs | 9 +++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/ethcore/service/src/service.rs b/ethcore/service/src/service.rs index 5f46799796a..f703329d611 100644 --- a/ethcore/service/src/service.rs +++ b/ethcore/service/src/service.rs @@ -29,7 +29,7 @@ use sync::PrivateTxHandler; use ethcore::client::{Client, ClientConfig, ChainNotify, ClientIoMessage}; use ethcore::miner::Miner; use ethcore::snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; -use ethcore::snapshot::{RestorationStatus}; +use ethcore::snapshot::{SnapshotService as _SnapshotService, RestorationStatus}; use ethcore::spec::Spec; use ethcore::account_provider::AccountProvider; @@ -168,6 +168,11 @@ impl ClientService { /// Get a handle to the database. pub fn db(&self) -> Arc { self.database.clone() } + + /// Shutdown the Client Service + pub fn shutdown(&self) { + self.snapshot.shutdown(); + } } /// IO interface for the Client handler diff --git a/ethcore/src/snapshot/service.rs b/ethcore/src/snapshot/service.rs index 17c362e0440..942015d0f10 100644 --- a/ethcore/src/snapshot/service.rs +++ b/ethcore/src/snapshot/service.rs @@ -743,6 +743,10 @@ impl SnapshotService for Service { trace!("Error sending snapshot service message: {:?}", e); } } + + fn shutdown(&self) { + self.abort_restore(); + } } impl Drop for Service { diff --git a/ethcore/src/snapshot/traits.rs b/ethcore/src/snapshot/traits.rs index 2b6ee9df9f4..d951f4c5341 100644 --- a/ethcore/src/snapshot/traits.rs +++ b/ethcore/src/snapshot/traits.rs @@ -54,4 +54,7 @@ pub trait SnapshotService : Sync + Send { /// Feed a raw block chunk to the service to be processed asynchronously. /// no-op if currently restoring. fn restore_block_chunk(&self, hash: H256, chunk: Bytes); + + /// Shutdown the Snapshot Service by aborting any ongoing restore + fn shutdown(&self); } diff --git a/parity/run.rs b/parity/run.rs index 73113055bbf..ec0294a43c1 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -880,7 +880,8 @@ fn execute_impl(cmd: RunCmd, logger: Arc, on_client_rq: inner: RunningClientInner::Full { informant, client, - keep_alive: Box::new((watcher, service, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)), + service: Arc::new(service), + keep_alive: Box::new((watcher, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)), } }) } @@ -902,6 +903,7 @@ enum RunningClientInner { Full { informant: Arc>, client: Arc, + service: Arc, keep_alive: Box, }, } @@ -920,11 +922,14 @@ impl RunningClient { drop(client); wait_for_drop(weak_client); }, - RunningClientInner::Full { informant, client, keep_alive } => { + RunningClientInner::Full { informant, client, service, keep_alive } => { info!("Finishing work, please wait..."); // Create a weak reference to the client so that we can wait on shutdown // until it is dropped let weak_client = Arc::downgrade(&client); + // Shutdown and drop the ServiceClient + service.shutdown(); + drop(service); // drop this stuff as soon as exit detected. drop(keep_alive); // to make sure timer does not spawn requests while shutdown is in progress From ed45654f644dcd7ceffcaf3896d7a9537a254c6d Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Mon, 28 May 2018 14:45:53 +0200 Subject: [PATCH 2/3] Rename `service` to `client_service` --- parity/run.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parity/run.rs b/parity/run.rs index 34cf541ead4..31f8779c0fa 100644 --- a/parity/run.rs +++ b/parity/run.rs @@ -885,7 +885,7 @@ fn execute_impl(cmd: RunCmd, logger: Arc, on_client_rq: rpc: rpc_direct, informant, client, - service: Arc::new(service), + client_service: Arc::new(service), keep_alive: Box::new((watcher, updater, ws_server, http_server, ipc_server, ui_server, secretstore_key_server, ipfs_server, event_loop)), } }) @@ -910,7 +910,7 @@ enum RunningClientInner { rpc: jsonrpc_core::MetaIoHandler>, informant: Arc>, client: Arc, - service: Arc, + client_service: Arc, keep_alive: Box, }, } @@ -948,14 +948,14 @@ impl RunningClient { drop(client); wait_for_drop(weak_client); }, - RunningClientInner::Full { rpc, informant, client, service, keep_alive } => { + RunningClientInner::Full { rpc, informant, client, client_service, keep_alive } => { info!("Finishing work, please wait..."); // Create a weak reference to the client so that we can wait on shutdown // until it is dropped let weak_client = Arc::downgrade(&client); // Shutdown and drop the ServiceClient - service.shutdown(); - drop(service); + client_service.shutdown(); + drop(client_service); // drop this stuff as soon as exit detected. drop(rpc); drop(keep_alive); From 0411ae71e9bafd9101380270978ce010220293c5 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Mon, 28 May 2018 16:24:31 +0200 Subject: [PATCH 3/3] Fix tests --- rpc/src/v1/tests/helpers/snapshot_service.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rpc/src/v1/tests/helpers/snapshot_service.rs b/rpc/src/v1/tests/helpers/snapshot_service.rs index 099773ab522..91cd14d73f1 100644 --- a/rpc/src/v1/tests/helpers/snapshot_service.rs +++ b/rpc/src/v1/tests/helpers/snapshot_service.rs @@ -50,4 +50,5 @@ impl SnapshotService for TestSnapshotService { fn abort_restore(&self) { } fn restore_state_chunk(&self, _hash: H256, _chunk: Bytes) { } fn restore_block_chunk(&self, _hash: H256, _chunk: Bytes) { } + fn shutdown(&self) { } }