From c834b5eecdde3587ad5d2ac757bd90ef0be5a63b Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Wed, 31 Jan 2018 12:33:19 +0000 Subject: [PATCH] pickup worker events, and free them. exponential backoff for continuously failing zones. git-svn-id: file:///svn/unbound/trunk@4479 be551aaa-1e26-0410-a405-d3ace91eadb9 --- daemon/daemon.c | 3 ++- daemon/worker.c | 8 ++++++++ services/authzone.c | 17 +++++++++++++++++ services/authzone.h | 9 +++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/daemon/daemon.c b/daemon/daemon.c index 6f82ca60a..c56581b8b 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -695,6 +695,8 @@ daemon_cleanup(struct daemon* daemon) daemon->respip_set = NULL; views_delete(daemon->views); daemon->views = NULL; + auth_zones_delete(daemon->env->auth_zones); + daemon->env->auth_zones = NULL; /* key cache is cleared by module desetup during next daemon_fork() */ daemon_remote_clear(daemon->rc); for(i=0; inum; i++) @@ -728,7 +730,6 @@ daemon_delete(struct daemon* daemon) rrset_cache_delete(daemon->env->rrset_cache); infra_delete(daemon->env->infra_cache); edns_known_options_delete(daemon->env); - auth_zones_delete(daemon->env->auth_zones); } ub_randfree(daemon->rand); alloc_clear(&daemon->superalloc); diff --git a/daemon/worker.c b/daemon/worker.c index a382bbb89..7caa11318 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -1738,6 +1738,14 @@ worker_init(struct worker* worker, struct config_file *cfg, comm_timer_set(worker->env.probe_timer, &tv); } } + /* zone transfer tasks, setup once per process, if any */ + if(worker->env.auth_zones +#ifndef THREADS_DISABLED + && worker->thread_num == 0 +#endif + ) { + auth_xfer_pickup_initial(worker->env.auth_zones, &worker->env); + } if(!worker->env.mesh || !worker->env.scratch_buffer) { worker_delete(worker); return 0; diff --git a/services/authzone.c b/services/authzone.c index 406ed8190..d3ec1e8d0 100644 --- a/services/authzone.c +++ b/services/authzone.c @@ -78,6 +78,8 @@ #define AUTH_PROBE_TIMEOUT_STOP 1000 /* msec */ /* auth transfer timeout for TCP connections, in msec */ #define AUTH_TRANSFER_TIMEOUT 10000 /* msec */ +/* auth transfer max backoff for failed tranfers and probes */ +#define AUTH_TRANSFER_MAX_BACKOFF 86400 /* sec */ /** pick up nextprobe task to start waiting to perform transfer actions */ static void xfr_set_timeout(struct auth_xfer* xfr, struct module_env* env, @@ -5086,6 +5088,21 @@ xfr_set_timeout(struct auth_xfer* xfr, struct module_env* env, if(xfr->expiry < wait) xfr->task_nextprobe->next_probe += xfr->expiry; else xfr->task_nextprobe->next_probe += wait; + if(!failure) xfr->task_nextprobe->backoff = 0; + } else { + if(!failure) { + xfr->task_nextprobe->backoff = 0; + } else { + if(xfr->task_nextprobe->backoff == 0) + xfr->task_nextprobe->backoff = 3; + else xfr->task_nextprobe->backoff *= 2; + if(xfr->task_nextprobe->backoff > + AUTH_TRANSFER_MAX_BACKOFF) + xfr->task_nextprobe->backoff = + AUTH_TRANSFER_MAX_BACKOFF; + } + xfr->task_nextprobe->next_probe += + xfr->task_nextprobe->backoff; } if(!xfr->task_nextprobe->timer) { diff --git a/services/authzone.h b/services/authzone.h index 7db4f4a56..93989cd2d 100644 --- a/services/authzone.h +++ b/services/authzone.h @@ -259,6 +259,8 @@ struct auth_nextprobe { /* module env for this task */ struct module_env* env; + /** increasing backoff for failures */ + time_t backoff; /** Timeout for next probe (for SOA) */ time_t next_probe; /** timeout callback for next_probe or expiry(if that is sooner). @@ -431,6 +433,13 @@ struct auth_zones* auth_zones_create(void); int auth_zones_apply_cfg(struct auth_zones* az, struct config_file* cfg, int setup); +/** initial pick up of worker timeouts, ties events to worker event loop + * @param az: auth zones structure + * @param env: worker env, of first worker that receives the events (if any) + * in its eventloop. + */ +void auth_xfer_pickup_initial(struct auth_zones* az, struct module_env* env); + /** * Delete auth zones structure */ -- 2.47.3