From 6db576195c4417bac663a05a12bd4b712c47ff2a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Wed, 1 May 2019 22:46:10 -0700 Subject: [PATCH] Improve DNS_Mgr I/O loop: prevent starvation due to busy Broker --- src/DNS_Mgr.cc | 15 +++++++++++++-- src/DNS_Mgr.h | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 3be59981a7..11f1e30037 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -392,6 +392,7 @@ DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode) successful = 0; failed = 0; nb_dns = nullptr; + next_timestamp = -1.0; } DNS_Mgr::~DNS_Mgr() @@ -1252,8 +1253,17 @@ void DNS_Mgr::GetFds(iosource::FD_Set* read, iosource::FD_Set* write, double DNS_Mgr::NextTimestamp(double* network_time) { - // This is kind of cheating ... - return asyncs_timeouts.size() ? timer_mgr->Time() : -1.0; + if ( asyncs_timeouts.empty() ) + // No pending requests. + return -1.0; + + if ( next_timestamp < 0 ) + // Store the timestamp to help prevent starvation by some other + // IOSource always trying to use the same timestamp + // (assuming network_time does actually increase). + next_timestamp = timer_mgr->Time(); + + return next_timestamp; } void DNS_Mgr::CheckAsyncAddrRequest(const IPAddr& addr, bool timeout) @@ -1382,6 +1392,7 @@ void DNS_Mgr::Flush() void DNS_Mgr::Process() { DoProcess(false); + next_timestamp = -1.0; } void DNS_Mgr::DoProcess(bool flush) diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index f6f62bd1ec..7c7ddc8738 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -236,6 +236,7 @@ protected: unsigned long num_requests; unsigned long successful; unsigned long failed; + double next_timestamp; }; extern DNS_Mgr* dns_mgr;