Skip to content

Commit

Permalink
lib-http: If connect fails, include attempt count and total time in e…
Browse files Browse the repository at this point in the history
…rror.

This will produce errors such as:
9002 connect(1.2.3.4:801) failed: Connection timed out in 1.001 secs (4 attempts in 4.706 secs)
  • Loading branch information
sirainen authored and GitLab committed May 8, 2016
1 parent 5d31e4b commit 9284599
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib-http/http-client-private.h
Expand Up @@ -220,6 +220,7 @@ struct http_client_queue {
connected IP */
unsigned int ips_connect_start_idx;

struct timeval first_connect_time;
unsigned int connect_attempts;

/* peers we are trying to connect to;
Expand Down
10 changes: 9 additions & 1 deletion src/lib-http/http-client-queue.c
Expand Up @@ -282,7 +282,8 @@ void http_client_queue_connection_setup(struct http_client_queue *queue)
http_client_peer_addr2str(addr), ssl);

array_append(&queue->pending_peers, &peer, 1);
queue->connect_attempts++;
if (queue->connect_attempts++ == 0)
queue->first_connect_time = ioloop_timeval;
}

/* start soft connect time-out (but only if we have another IP left) */
Expand Down Expand Up @@ -401,6 +402,13 @@ http_client_queue_connection_failure(struct http_client_queue *queue,
queue->connect_attempts >= set->max_connect_attempts) {
http_client_queue_debug(queue,
"Failed to set up any connection; failing all queued requests");
if (queue->connect_attempts > 1) {
unsigned int total_msecs =
timeval_diff_msecs(&ioloop_timeval, &queue->first_connect_time);
reason = t_strdup_printf("%s (%u attempts in %u.%03u secs)",
reason, queue->connect_attempts,
total_msecs/1000, total_msecs%1000);
}
queue->connect_attempts = 0;
http_client_queue_fail(queue,
HTTP_CLIENT_REQUEST_ERROR_CONNECT_FAILED, reason);
Expand Down

0 comments on commit 9284599

Please sign in to comment.