Skip to content

Commit

Permalink
lib-http: client: Fixed i_unreached() failure occurring when a host's…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
stephanbosch committed Feb 23, 2017
1 parent d85468c commit 97a8fde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/lib-http/http-client-private.h
Expand Up @@ -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 *
Expand Down
7 changes: 5 additions & 2 deletions src/lib-http/http-client-queue.c
Expand Up @@ -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 */
Expand Down

0 comments on commit 97a8fde

Please sign in to comment.