From 05e721c729fa857deb188d5d04f2200c7dcf4983 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Tue, 4 Apr 2017 00:32:07 +0200 Subject: [PATCH] lib-http: client: Fixed race condition between DNS refresh lookup and a soft connection timeout. The refreshing DNS lookup cleared all the IPs, but the soft connection timeout (and maybe other code) still relied on them. Adding tests everywhere for host->ips_count == 0 is annoying, so I changed the DNS lookup code such that the stale IPs remain present while the DNS lookup is being performed. The pending lookup prevents new connections through http_client_host_refresh(), so this will not create potentially useless connections. --- src/lib-http/http-client-host.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index b6f68f6981..dc3e592385 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -108,8 +108,6 @@ static void http_client_host_lookup i_assert(!host->explicit_ip); i_assert(host->dns_lookup == NULL); - host->ips_count = 0; - if (client->set.dns_client != NULL) { http_client_host_debug(host, "Performing asynchronous DNS lookup"); @@ -147,9 +145,7 @@ static void http_client_host_lookup host->ips_count = ips_count; host->ips = i_new(struct ip_addr, ips_count); memcpy(host->ips, ips, ips_count * sizeof(*ips)); - } - if (host->ips_count > 0) { host->ips_timeout = ioloop_timeval; timeval_add_msecs(&host->ips_timeout, client->set.dns_ttl_msecs); }