aboutsummaryrefslogtreecommitdiffstats
path: root/main/opennhrp/0007-fix-race-condition-to-stop-processing-dns-requests.patch
blob: b25c53a68dc4ac3559e98cde7eab1c90b2181a51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
From 8be8f8df88490f6d9686fcbf2cd50a5b15e2c835 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Fri, 24 Jul 2015 10:34:13 +0300
Subject: [PATCH] fix race condition to stop processing dns requests

ev_timer_again stops the timer if .repeat is zero, but ares_timeout
returns zero timeout if there's events that are already expired.
This becomes issue if we were busy processing something else and
then c-ares timeouts expire meanwhile, we'd end up not handling them.
As a workaround schedule it with small timeout, while this can
postpone timeout handling quite a bit, in practice this should
work well enough.
---
 nhrp/nhrp_address.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/nhrp/nhrp_address.c b/nhrp/nhrp_address.c
index 1ac9fa3..9169cd8 100644
--- a/nhrp/nhrp_address.c
+++ b/nhrp/nhrp_address.c
@@ -47,7 +47,10 @@ static void ares_prepare_cb(struct ev_loop *loop, struct ev_prepare *w, int reve
 
 	tv = ares_timeout(r->channel, NULL, &tvbuf);
 	if (tv != NULL) {
-		r->timeout.repeat = tv->tv_sec + tv->tv_usec * 1e-6;
+		if (tv->tv_sec || tv->tv_usec)
+			r->timeout.repeat = tv->tv_sec + tv->tv_usec * 1e-6;
+		else
+			r->timeout.repeat = 1e-6;
 		ev_timer_again(&r->timeout);
 	} else {
 		ev_timer_stop(&r->timeout);
-- 
2.4.6