[nginx] Resolver: fixed CNAME processing for several requests.

Maxim Dounin mdounin at mdounin.ru
Tue Jan 26 16:27:39 UTC 2016


details:   http://hg.nginx.org/nginx/rev/838946300825
branches:  stable-1.8
changeset: 6357:838946300825
user:      Ruslan Ermilov <ru at nginx.com>
date:      Tue Jan 26 16:46:38 2016 +0300
description:
Resolver: fixed CNAME processing for several requests.

When several requests were waiting for a response, then after getting
a CNAME response only the last request was properly processed, while
others were left waiting.

diffstat:

 src/core/ngx_resolver.c |  21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)

diffs (66 lines):

diff --git a/src/core/ngx_resolver.c b/src/core/ngx_resolver.c
--- a/src/core/ngx_resolver.c
+++ b/src/core/ngx_resolver.c
@@ -473,7 +473,7 @@ ngx_resolve_name_locked(ngx_resolver_t *
     ngx_int_t             rc;
     ngx_uint_t            naddrs;
     ngx_addr_t           *addrs;
-    ngx_resolver_ctx_t   *next;
+    ngx_resolver_ctx_t   *next, *last;
     ngx_resolver_node_t  *rn;
 
     ngx_strlow(ctx->name.data, ctx->name.data, ctx->name.len);
@@ -484,6 +484,9 @@ ngx_resolve_name_locked(ngx_resolver_t *
 
     if (rn) {
 
+        /* ctx can be a list after NGX_RESOLVE_CNAME */
+        for (last = ctx; last->next; last = last->next);
+
         if (rn->valid >= ngx_time()) {
 
             ngx_log_debug0(NGX_LOG_DEBUG_CORE, r->log, 0, "resolve cached");
@@ -511,7 +514,7 @@ ngx_resolve_name_locked(ngx_resolver_t *
                     }
                 }
 
-                ctx->next = rn->waiting;
+                last->next = rn->waiting;
                 rn->waiting = NULL;
 
                 /* unlock name mutex */
@@ -557,7 +560,7 @@ ngx_resolve_name_locked(ngx_resolver_t *
                 return ngx_resolve_name_locked(r, ctx);
             }
 
-            ctx->next = rn->waiting;
+            last->next = rn->waiting;
             rn->waiting = NULL;
 
             /* unlock name mutex */
@@ -590,7 +593,7 @@ ngx_resolve_name_locked(ngx_resolver_t *
                 ngx_add_timer(ctx->event, ctx->timeout);
             }
 
-            ctx->next = rn->waiting;
+            last->next = rn->waiting;
             rn->waiting = ctx;
             ctx->state = NGX_AGAIN;
 
@@ -661,8 +664,14 @@ ngx_resolve_name_locked(ngx_resolver_t *
         ngx_resolver_free(r, rn->name);
         ngx_resolver_free(r, rn);
 
-        ctx->state = NGX_RESOLVE_NXDOMAIN;
-        ctx->handler(ctx);
+        do {
+            ctx->state = NGX_RESOLVE_NXDOMAIN;
+            next = ctx->next;
+
+            ctx->handler(ctx);
+
+            ctx = next;
+        } while (ctx);
 
         return NGX_OK;
     }



More information about the nginx-devel mailing list