From 97a8fde13ea33b09163c45d978a4949043f189c5 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Thu, 23 Feb 2017 19:38:31 +0100 Subject: [PATCH] lib-http: client: Fixed i_unreached() failure occurring when a host's list of IPs changes while a connection is still pending. In that case, the IP of the pending connection may no longer be associated with that host. If the IP was not found anymore, the i_unreached() error occurred. --- src/lib-http/http-client-private.h | 12 +++++++----- src/lib-http/http-client-queue.c | 7 +++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index c25c3a0a3d..52fd57e120 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -516,17 +516,19 @@ void http_client_queue_switch_ioloop(struct http_client_queue *queue); * Host */ -static inline unsigned int +static inline bool http_client_host_get_ip_idx(struct http_client_host *host, - const struct ip_addr *ip) + const struct ip_addr *ip, unsigned int *idx_r) { unsigned int i; for (i = 0; i < host->ips_count; i++) { - if (net_ip_compare(&host->ips[i], ip)) - return i; + if (net_ip_compare(&host->ips[i], ip)) { + *idx_r = i; + return TRUE; + } } - i_unreached(); + return FALSE; } struct http_client_host * diff --git a/src/lib-http/http-client-queue.c b/src/lib-http/http-client-queue.c index 496dc5e8a2..16d74c8406 100644 --- a/src/lib-http/http-client-queue.c +++ b/src/lib-http/http-client-queue.c @@ -430,8 +430,11 @@ http_client_queue_connection_success(struct http_client_queue *queue, if (queue->host->dns_lookup == NULL && queue->addr.type != HTTP_CLIENT_PEER_ADDR_UNIX) { /* we achieved at least one connection the the addr->ip */ - queue->ips_connect_start_idx = - http_client_host_get_ip_idx(queue->host, &addr->a.tcp.ip); + if (!http_client_host_get_ip_idx(queue->host, + &addr->a.tcp.ip, &queue->ips_connect_start_idx)) { + /* list of IPs changed during connect */ + queue->ips_connect_start_idx = 0; + } } /* reset attempt counter */