diff --git a/src/avalanche.h b/src/avalanche.h --- a/src/avalanche.h +++ b/src/avalanche.h @@ -289,6 +289,7 @@ private: void runEventLoop(); + void clearTimedoutRequests(); std::vector getInvsForNextPoll() const; NodeId getSuitableNodeToQuery(); diff --git a/src/avalanche.cpp b/src/avalanche.cpp --- a/src/avalanche.cpp +++ b/src/avalanche.cpp @@ -343,17 +343,21 @@ return NO_NODE; } -void AvalancheProcessor::runEventLoop() { +void AvalancheProcessor::clearTimedoutRequests() { auto now = std::chrono::steady_clock::now(); - { - // Clear expired requests. - auto w = queries.getWriteView(); - auto it = w->get().begin(); - while (it != w->get().end() && it->timeout < now) { - w->get().erase(it++); - } + // Clear expired requests. + auto w = queries.getWriteView(); + auto it = w->get().begin(); + while (it != w->get().end() && it->timeout < now) { + w->get().erase(it++); } +} + +void AvalancheProcessor::runEventLoop() { + // First things first, check if we have requests that timed out and clear + // them. + clearTimedoutRequests(); std::vector invs = getInvsForNextPoll(); if (invs.empty()) {