]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: If connect fails, include attempt count and total time in error.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 5 May 2016 21:17:31 +0000 (00:17 +0300)
committerGitLab <gitlab@git.dovecot.net>
Sun, 8 May 2016 19:44:50 +0000 (22:44 +0300)
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)

src/lib-http/http-client-private.h
src/lib-http/http-client-queue.c

index 48612813b8a0101036a09c105523e2d050acfb98..29fd66aa85ce1ce7517352a64da5144beb9d0a30 100644 (file)
@@ -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;
index 7b2bbff90b291ad3bafac5312a99a188bbbfb2f8..d6dea62ae04910698ad3f93bf1e40ab2a16be3e9 100644 (file)
@@ -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) */
@@ -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);