From 9b3dd7002dfd3d0a80b66539edb0b5cbf7c6e403 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Wed, 17 Jun 2026 13:06:40 -0400 Subject: [PATCH 1/2] fix: Allocate TaggedCache::getKeys() memory outside of lock - Uses a loop in case the size grows while the lock is free. Guarantees the result vector will not need to allocate under lock. --- include/xrpl/basics/TaggedCache.ipp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index cee02749c62..ef9942ab869 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -2,6 +2,7 @@ #include #include +#include namespace xrpl { @@ -536,8 +537,15 @@ TaggedCache v; { - std::scoped_lock const lock(mutex_); - v.reserve(cache_.size()); + std::unique_lock lock(mutex_); + for (int size = cache_.size(); v.capacity() < size; size = cache_.size()) + { + ScopeUnlock const unlock(lock); + v.reserve(size); + } + XRPL_ASSERT(lock.owns_lock(), "xrpl::TaggedCache::getKeys(): owns lock"); + XRPL_ASSERT( + v.capacity() >= cache_.size(), "xrpl::TaggedCache::getKeys(): sufficient capacity"); for (auto const& _ : cache_) v.push_back(_.first); } From 054284701e88e134ebb6481109eab9eb6eb56530 Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Wed, 17 Jun 2026 15:20:48 -0400 Subject: [PATCH 2/2] Apply suggestion from @xrplf-ai-reviewer[bot] Co-authored-by: xrplf-ai-reviewer[bot] <266832837+xrplf-ai-reviewer[bot]@users.noreply.github.com> --- include/xrpl/basics/TaggedCache.ipp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/xrpl/basics/TaggedCache.ipp b/include/xrpl/basics/TaggedCache.ipp index ef9942ab869..8e235dbb238 100644 --- a/include/xrpl/basics/TaggedCache.ipp +++ b/include/xrpl/basics/TaggedCache.ipp @@ -538,7 +538,7 @@ TaggedCache