From 6124bf612ccb79b037eac221dacf646182a86e1d Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 16 Apr 2020 18:53:29 -0700 Subject: [PATCH] modules/m_vm_fetch: Allow prev_fetch to check if events arrived elsehow while waiting. --- modules/m_vm_fetch.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/modules/m_vm_fetch.cc b/modules/m_vm_fetch.cc index 632a3e7e5..f00f274d7 100644 --- a/modules/m_vm_fetch.cc +++ b/modules/m_vm_fetch.cc @@ -605,12 +605,25 @@ ircd::m::vm::fetch::prev(const event &event, ctx::when_all(begin(futures), end(futures)) }; - // yields context - const bool done + const auto timeout { - fetching.wait(seconds(event_timeout), std::nothrow) + now() + seconds(event_timeout) }; + // Rather than waiting for all of the events to arrive or for the entire + // timeout to expire, we check if the sought events made it to the server + // in the meantime. If so we can drop these requests and bail. + while(now() < timeout) + { + // Wait for an interval to give this loop some iterations. + if(fetching.wait(milliseconds(500), std::nothrow)) + break; + + // Check for satisfaction. + if((prev_exists = prev.prev_events_exist()) == prev_count) + return; + } + // evaluate results for(auto &future : futures) try {