From e7b070df0143d48b3ae2494802f21d7fa3936200 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 14 Sep 2022 14:40:51 +1000 Subject: [PATCH] Work around a RocksDB shutdown bug --- zebra-state/src/service/finalized_state/disk_db.rs | 6 ++++++ zebra-state/src/service/tests.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/zebra-state/src/service/finalized_state/disk_db.rs b/zebra-state/src/service/finalized_state/disk_db.rs index 85add5d279f..cccdef908fd 100644 --- a/zebra-state/src/service/finalized_state/disk_db.rs +++ b/zebra-state/src/service/finalized_state/disk_db.rs @@ -684,6 +684,12 @@ impl DiskDb { self.db.flush().expect("flush is successful"); // But we should call `cancel_all_background_work` before Zebra exits. + // + // In some tests, we need to drop() the state service before the test function returns, + // and sleep() until all the other threads exit. + // (This seems to be a bug in RocksDB: cancel_all_background_work() should wait until + // all the threads have cleaned up.) + // // If we don't, we see these kinds of errors: // ``` // pthread lock: Invalid argument diff --git a/zebra-state/src/service/tests.rs b/zebra-state/src/service/tests.rs index f097e8fb6bb..35a781dc85b 100644 --- a/zebra-state/src/service/tests.rs +++ b/zebra-state/src/service/tests.rs @@ -465,10 +465,14 @@ proptest! { expected_transparent_pool ); } + + // Work around a RocksDB shutdown bug, see DiskDb::shutdown() for details. + std::mem::drop(state_service); + std::thread::sleep(Duration::from_secs(1)); } } -// This test sleeps, so we only ever want to run it once +// This test sleeps for every block, so we only ever want to run it once proptest! { #![proptest_config( proptest::test_runner::Config::with_cases(1) @@ -539,6 +543,10 @@ proptest! { prop_assert_eq!(latest_chain_tip.best_tip_height(), Some(expected_block.height)); prop_assert_eq!(chain_tip_change.last_tip_change(), Some(expected_action)); } + + // Work around a RocksDB shutdown bug, see DiskDb::shutdown() for details. + std::mem::drop(state_service); + std::thread::sleep(Duration::from_secs(1)); } }