From 6e829789313b9772b2bbc305abcad05285ab89c7 Mon Sep 17 00:00:00 2001 From: carllin Date: Fri, 23 Aug 2019 23:40:20 -0700 Subject: [PATCH] Fix race with LedgerCleanupService (#5622) --- core/src/blocktree/rooted_slot_iterator.rs | 25 ++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/core/src/blocktree/rooted_slot_iterator.rs b/core/src/blocktree/rooted_slot_iterator.rs index 450650e067..f3b691c687 100644 --- a/core/src/blocktree/rooted_slot_iterator.rs +++ b/core/src/blocktree/rooted_slot_iterator.rs @@ -29,16 +29,23 @@ impl<'a> Iterator for RootedSlotIterator<'a> { .find(|x| self.blocktree.is_root(**x)) .cloned(); - rooted_slot.map(|rooted_slot| { - let slot_meta = self - .blocktree - .meta(rooted_slot) - .expect("Database failure, couldnt fetch SlotMeta") - .expect("SlotMeta in iterator didn't exist"); + rooted_slot + .map(|rooted_slot| { + let slot_meta = self + .blocktree + .meta(rooted_slot) + .expect("Database failure, couldnt fetch SlotMeta"); - self.next_slots = slot_meta.next_slots.clone(); - (rooted_slot, slot_meta) - }) + if slot_meta.is_none() { + warn!("Rooted SlotMeta was deleted in between checking is_root and fetch"); + } + + slot_meta.map(|slot_meta| { + self.next_slots = slot_meta.next_slots.clone(); + (rooted_slot, slot_meta) + }) + }) + .unwrap_or(None) } }