From: Otto Date: Tue, 17 Aug 2021 10:23:40 +0000 (+0200) Subject: From review feedback: only inc s_almost_expired_tasks_run after task has ended withou... X-Git-Tag: dnsdist-1.7.0-alpha1~64^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10598%2Fhead;p=thirdparty%2Fpdns.git From review feedback: only inc s_almost_expired_tasks_run after task has ended without exceptions and check for nullptr function in task record. --- diff --git a/pdns/recursordist/rec-taskqueue.cc b/pdns/recursordist/rec-taskqueue.cc index 9bd0cd6c3b..2705c59b85 100644 --- a/pdns/recursordist/rec-taskqueue.cc +++ b/pdns/recursordist/rec-taskqueue.cc @@ -32,7 +32,6 @@ static pdns::stat_t s_almost_expired_tasks_exceptions; static void resolve(const struct timeval& now, bool logErrors, const pdns::ResolveTask& task) { - ++s_almost_expired_tasks_run; const string msg = "Exception while running a background ResolveTask"; SyncRes sr(now); vector ret; @@ -40,6 +39,7 @@ static void resolve(const struct timeval& now, bool logErrors, const pdns::Resol try { g_log << Logger::Debug << "TaskQueue: resolving " << task.d_qname.toString() << '|' << QType(task.d_qtype).toString() << endl; int res = sr.beginResolve(task.d_qname, QType(task.d_qtype), QClass::IN, ret); + ++s_almost_expired_tasks_run; g_log << Logger::Debug << "TaskQueue: DONE resolving " << task.d_qname.toString() << '|' << QType(task.d_qtype).toString() << ": " << res << endl; } catch (const std::exception& e) { diff --git a/pdns/recursordist/taskqueue.cc b/pdns/recursordist/taskqueue.cc index c1aa80c38f..11be99ef20 100644 --- a/pdns/recursordist/taskqueue.cc +++ b/pdns/recursordist/taskqueue.cc @@ -61,8 +61,12 @@ bool TaskQueue::runOnce(bool logErrors) return false; } ResolveTask task = pop(); + if (task.func == nullptr) { + g_log << Logger::Debug << "TaskQueue: null task for " << task.d_qname.toString() << '|' << QType(task.d_qtype).toString() << endl; + return true; + } struct timeval now; - gettimeofday(&now, 0); + Utility::gettimeofday(&now); if (task.d_deadline >= now.tv_sec) { task.func(now, logErrors, task); } diff --git a/pdns/ws-recursor.cc b/pdns/ws-recursor.cc index 44e768b532..181a0f318e 100644 --- a/pdns/ws-recursor.cc +++ b/pdns/ws-recursor.cc @@ -1057,7 +1057,7 @@ const std::map MetricDefinitionStorage::metrics = { "almost-expired-run", MetricDefinition(PrometheusMetricType::counter, - "number of almost-expired tasks run")}, + "number of almost-expired tasks run to completion")}, { "almost-expired-exceptions", MetricDefinition(PrometheusMetricType::counter,