From ac570e7353ae87558fb824d72d2169fd73de638f Mon Sep 17 00:00:00 2001 From: skoupidi Date: Tue, 4 Jun 2024 16:12:37 +0300 Subject: [PATCH] darkfid: properly stop rpc client on termination --- bin/darkfid/src/main.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/darkfid/src/main.rs b/bin/darkfid/src/main.rs index f656abe68..f5df2a22b 100644 --- a/bin/darkfid/src/main.rs +++ b/bin/darkfid/src/main.rs @@ -345,7 +345,7 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { let task = StoppableTask::new(); task.clone().start( - miner_task(darkfid, recipient, blockchain_config.skip_sync, ex.clone()), + miner_task(darkfid.clone(), recipient, blockchain_config.skip_sync, ex.clone()), |res| async move { match res { Ok(()) | Err(Error::MinerTaskStopped) => { /* Do nothing */ } @@ -360,7 +360,7 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { } else { let task = StoppableTask::new(); task.clone().start( - consensus_task(darkfid, ex.clone()), + consensus_task(darkfid.clone(), ex.clone()), |res| async move { match res { Ok(()) | Err(Error::ConsensusTaskStopped) => { /* Do nothing */ } @@ -392,5 +392,10 @@ async fn realmain(args: Args, ex: Arc>) -> Result<()> { let flushed_bytes = sled_db.flush_async().await?; info!(target: "darkfid", "Flushed {} bytes", flushed_bytes); + if let Some(ref rpc_client) = darkfid.rpc_client { + info!(target: "darkfid", "Stopping JSON-RPC client..."); + rpc_client.lock().await.client.stop().await; + }; + Ok(()) }