Unverified Commit da59c6ae authored by jthomson04's avatar jthomson04 Committed by GitHub
Browse files

fix: Don't recursively drop blocks in KVBM (#4995)


Signed-off-by: default avatarjthomson04 <jwillthomson19@gmail.com>
parent 15b49818
......@@ -650,6 +650,26 @@ impl<S: Storage, L: LocalityProvider, M: BlockMetadata> Drop for MutableBlock<S,
{
tracing::warn!("block pool shutdown before block was returned");
}
// Iteratively drop the parent chain to avoid stack overflow.
// Without this, dropping a leaf block with thousands of ancestors would cause
// thousands of nested drop() calls, overflowing the stack.
let mut current_parent = self.parent.take();
while let Some(arc_parent) = current_parent {
// Try to get exclusive ownership of the parent
match Arc::try_unwrap(arc_parent) {
Ok(mut parent) => {
// We own this parent exclusively - take its parent to continue the chain.
// When `parent` drops at the end of this scope, its `parent` field is None,
// so no recursive drop occurs.
current_parent = parent.parent.take();
}
Err(_) => {
// Someone else has a reference to this parent, they'll handle the drop
break;
}
}
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment