From 3dc70af0678f9a92cf02e80140cc2becc83f9b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Fri, 3 May 2024 12:20:52 +0200 Subject: [PATCH] Wait until fair queue source drains before removal (#4597) --- nano/core_test/fair_queue.cpp | 19 +++++++++++-------- nano/node/fair_queue.hpp | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/nano/core_test/fair_queue.cpp b/nano/core_test/fair_queue.cpp index d60dda7855..eda3d7fc8b 100644 --- a/nano/core_test/fair_queue.cpp +++ b/nano/core_test/fair_queue.cpp @@ -260,17 +260,20 @@ TEST (fair_queue, cleanup) ASSERT_EQ (queue.size ({ source_enum::live, channel2 }), 1); ASSERT_EQ (queue.size ({ source_enum::live, channel3 }), 1); - // Either closing or resetting the channel should remove it from the queue + // Either closing or resetting the channel should make it eligible for cleanup channel1->close (); channel2.reset (); - ASSERT_TRUE (queue.periodic_update ()); + ASSERT_TRUE (queue.periodic_update (0s)); - // Only channel 3 should remain - ASSERT_EQ (queue.size (), 1); - ASSERT_EQ (queue.queues_size (), 1); + // Until the queue is drained, the entries are still present + ASSERT_EQ (queue.size (), 3); + ASSERT_EQ (queue.queues_size (), 3); - ASSERT_EQ (queue.size ({ source_enum::live, channel1 }), 0); - ASSERT_EQ (queue.size ({ source_enum::live, channel2 }), 0); - ASSERT_EQ (queue.size ({ source_enum::live, channel3 }), 1); + queue.next_batch (999); + + ASSERT_TRUE (queue.periodic_update (0s)); + + ASSERT_TRUE (queue.empty ()); + ASSERT_EQ (queue.queues_size (), 1); } diff --git a/nano/node/fair_queue.hpp b/nano/node/fair_queue.hpp index 738bd43ec7..52bdcc34d0 100644 --- a/nano/node/fair_queue.hpp +++ b/nano/node/fair_queue.hpp @@ -330,7 +330,7 @@ class fair_queue final iterator = queues.end (); erase_if (queues, [] (auto const & entry) { - return !entry.first.alive (); + return entry.second.empty () && !entry.first.alive (); }); }