Skip to content

Commit

Permalink
Work around a RocksDB shutdown bug
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Sep 14, 2022
1 parent 37b20c0 commit 5e7943a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions zebra-state/src/service/finalized_state/disk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion zebra-state/src/service/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 5e7943a

Please sign in to comment.