diff --git a/substrate/bin/node/cli/tests/running_the_node_and_interrupt.rs b/substrate/bin/node/cli/tests/running_the_node_and_interrupt.rs index ecdb4d7671..35f0fc1066 100644 --- a/substrate/bin/node/cli/tests/running_the_node_and_interrupt.rs +++ b/substrate/bin/node/cli/tests/running_the_node_and_interrupt.rs @@ -38,6 +38,7 @@ async fn running_the_node_works_and_can_be_interrupted() { Command::new(cargo_bin("substrate")) .args(&["--dev", "-d"]) .arg(base_path.path()) + .arg("--db=paritydb") .arg("--no-hardware-benchmarks") .spawn() .unwrap(), @@ -52,6 +53,12 @@ async fn running_the_node_works_and_can_be_interrupted() { "the process must exit gracefully after signal {}", signal, ); + // Check if the database was closed gracefully. If it was not, + // there may exist a ref cycle that prevents the Client from being dropped properly. + // + // parity-db only writes the stats file on clean shutdown. + let stats_file = base_path.path().join("chains/dev/paritydb/full/stats.txt"); + assert!(std::path::Path::exists(&stats_file)); } run_command_and_kill(SIGINT).await; diff --git a/substrate/client/consensus/babe/src/lib.rs b/substrate/client/consensus/babe/src/lib.rs index 490fdfb174..683df9ddac 100644 --- a/substrate/client/consensus/babe/src/lib.rs +++ b/substrate/client/consensus/babe/src/lib.rs @@ -1783,9 +1783,13 @@ where // startup rather than waiting until importing the next epoch change block. prune_finalized(client.clone(), &mut epoch_changes.shared_data())?; - let client_clone = client.clone(); + let client_weak = Arc::downgrade(&client); let on_finality = move |summary: &FinalityNotification| { - aux_storage_cleanup(client_clone.as_ref(), summary) + if let Some(client) = client_weak.upgrade() { + aux_storage_cleanup(client.as_ref(), summary) + } else { + Default::default() + } }; client.register_finality_action(Box::new(on_finality));