From 158c918a11748819ad19b8c792463e3723dbc039 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Wed, 23 Mar 2005 00:30:56 +0000 Subject: [PATCH] Fix DNS-related timer assertion failure. git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1336 c9e4aea6-c8fd-4c43-8297-357d70d61c8c --- ChangeLog | 12 ++++++++++++ ircd/ircd_events.c | 11 +++++++++-- ircd/ircd_res.c | 14 +++++++++----- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a11693..9c2c9bf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-03-22 Michael Poole + + * ircd/ircd_events.c (timer_chg): Properly change a timer that is + in the middle of executing its expiration event. + + * ircd/ircd_res.c (check_resolver_timeout): Simplify the test for + whether to use timer_chg() or timer_add(). + (timeout_resolver): Do not try to re-schedule the DNS timeout + unless it is the expiration event. + (do_query_number): Properly initialize request->state. + (res_readreply): Mention the response code that was bad. + 2005-03-22 Michael Poole * ircd/engine_kqueue.c (engine_delete): The kernel removes diff --git a/ircd/ircd_events.c b/ircd/ircd_events.c index 29b81a5..2de7f20 100644 --- a/ircd/ircd_events.c +++ b/ircd/ircd_events.c @@ -525,12 +525,19 @@ timer_chg(struct Timer* timer, enum TimerType type, time_t value) "timeout %Tu", timer, timer_to_name(timer->t_type), timer->t_value, timer_to_name(type), value)); - gen_dequeue(timer); /* remove the timer from the queue */ - timer->t_type = type; /* Set the new type and value */ timer->t_value = value; timer->t_expire = 0; + /* If the timer expiration callback tries to change the timer + * expiration, flag the timer but do not dequeue it yet. + */ + if (timer->t_header.gh_flags & GEN_MARKED) + { + timer->t_header.gh_flags |= GEN_READD; + return; + } + gen_dequeue(timer); /* remove the timer from the queue */ timer_enqueue(timer); /* re-queue the timer */ } diff --git a/ircd/ircd_res.c b/ircd/ircd_res.c index 22d30b1..8e9f33c 100644 --- a/ircd/ircd_res.c +++ b/ircd/ircd_res.c @@ -278,23 +278,26 @@ check_resolver_timeout(time_t when) { if (when > CurrentTime + AR_TTL) when = CurrentTime + AR_TTL; - if (!t_active(&res_timeout) || !t_onqueue(&res_timeout)) - timer_add(&res_timeout, timeout_resolver, NULL, TT_ABSOLUTE, when); - else if (when < t_expire(&res_timeout)) + if (t_onqueue(&res_timeout)) timer_chg(&res_timeout, TT_ABSOLUTE, when); + else + timer_add(&res_timeout, timeout_resolver, NULL, TT_ABSOLUTE, when); } /** Drop pending DNS lookups which have timed out. * @param[in] notused Timer event data (ignored). */ static void -timeout_resolver(struct Event *notused) +timeout_resolver(struct Event *ev) { struct dlink *ptr, *next_ptr; struct reslist *request; time_t next_time = 0; time_t timeout = 0; + if (ev_type(ev) != ET_EXPIRE) + return; + for (ptr = request_list.next; ptr != &request_list; ptr = next_ptr) { next_ptr = ptr->next; @@ -509,6 +512,7 @@ do_query_number(const struct DNSQuery *query, const struct irc_in_addr *addr, if (request == NULL) { request = make_request(query); + request->state= REQ_PTR; request->type = T_PTR; memcpy(&request->addr, addr, sizeof(request->addr)); request->name = (char *)MyMalloc(HOSTLEN + 1); @@ -800,7 +804,7 @@ res_readreply(struct Event *ev) * If a bad error was returned, we stop here and don't send * send any more (no retries granted). */ - Debug((DEBUG_DNS, "Request %p has bad response (state %d type %d)", request, request->state, request->type)); + Debug((DEBUG_DNS, "Request %p has bad response (state %d type %d rcode %d)", request, request->state, request->type, header->rcode)); (*request->query.callback)(request->query.vptr, 0); rem_request(request); } -- 2.20.1