[PATCH] Upstream: limited next_upstream time and tries when resolving DNS

Gu Feng flygoast at 126.com
Mon Oct 27 07:27:03 UTC 2014


# HG changeset patch
# User Gu Feng <flygoast at 126.com>
# Date 1414394704 -28800
#      Mon Oct 27 15:25:04 2014 +0800
# Node ID a7d62f0f3000d156477f556e5cb307f229fe6301
# Parent  973fded4f461f3a397779b3a1dc80881b1b34974
Upstream: limited next_upstream time and tries when resolving DNS.

When got multiple upstream IP addresses using DNS resolving, the number of
upstreams tries and the maxinum time spent for these tries were not affected.
This patch fixed it.

diff -r 973fded4f461 -r a7d62f0f3000 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c	Wed Oct 15 22:57:23 2014 +0400
+++ b/src/http/ngx_http_upstream.c	Mon Oct 27 15:25:04 2014 +0800
@@ -613,6 +613,14 @@ ngx_http_upstream_init_request(ngx_http_
                 return;
             }
 
+            u->peer.start_time = ngx_current_msec;
+
+            if (u->conf->next_upstream_tries
+                && u->peer.tries > u->conf->next_upstream_tries)
+            {
+                u->peer.tries = u->conf->next_upstream_tries;
+            }
+
             ngx_http_upstream_connect(r, u);
 
             return;
@@ -974,6 +982,14 @@ ngx_http_upstream_resolve_handler(ngx_re
     ngx_resolve_name_done(ctx);
     ur->ctx = NULL;
 
+    u->peer.start_time = ngx_current_msec;
+
+    if (u->conf->next_upstream_tries
+        && u->peer.tries > u->conf->next_upstream_tries)
+    {
+        u->peer.tries = u->conf->next_upstream_tries;
+    }
+
     ngx_http_upstream_connect(r, u);
 
 failed:



More information about the nginx-devel mailing list