[nginx] Resolver: notify all waiting requests on timeout.

Maxim Dounin mdounin at mdounin.ru
Tue Sep 16 14:42:00 UTC 2014


details:   http://hg.nginx.org/nginx/rev/60d2cb03faee
branches:  stable-1.6
changeset: 5840:60d2cb03faee
user:      Ruslan Ermilov <ru at nginx.com>
date:      Tue Aug 19 15:43:26 2014 +0400
description:
Resolver: notify all waiting requests on timeout.

If a "resolver_timeout" occurs, only the first waiting request
was notified.  Other requests may hang forever.

diffstat:

 src/core/ngx_resolver.c |  30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diffs (68 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
@@ -417,7 +417,7 @@ ngx_resolve_name_done(ngx_resolver_ctx_t
 
     /* lock name mutex */
 
-    if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) {
+    if (ctx->state == NGX_AGAIN) {
 
         hash = ngx_crc32_short(ctx->name.data, ctx->name.len);
 
@@ -664,7 +664,7 @@ ngx_resolve_name_locked(ngx_resolver_t *
         }
 
         ctx->event->handler = ngx_resolver_timeout_handler;
-        ctx->event->data = ctx;
+        ctx->event->data = rn;
         ctx->event->log = r->log;
         ctx->ident = -1;
 
@@ -857,7 +857,7 @@ ngx_resolve_addr(ngx_resolver_ctx_t *ctx
     }
 
     ctx->event->handler = ngx_resolver_timeout_handler;
-    ctx->event->data = ctx;
+    ctx->event->data = rn;
     ctx->event->log = r->log;
     ctx->ident = -1;
 
@@ -949,7 +949,7 @@ ngx_resolve_addr_done(ngx_resolver_ctx_t
 
     /* lock addr mutex */
 
-    if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) {
+    if (ctx->state == NGX_AGAIN) {
 
         switch (ctx->addr.sockaddr->sa_family) {
 
@@ -2791,13 +2791,21 @@ done:
 static void
 ngx_resolver_timeout_handler(ngx_event_t *ev)
 {
-    ngx_resolver_ctx_t  *ctx;
-
-    ctx = ev->data;
-
-    ctx->state = NGX_RESOLVE_TIMEDOUT;
-
-    ctx->handler(ctx);
+    ngx_resolver_ctx_t   *ctx, *next;
+    ngx_resolver_node_t  *rn;
+
+    rn = ev->data;
+    ctx = rn->waiting;
+    rn->waiting = NULL;
+
+    do {
+        ctx->state = NGX_RESOLVE_TIMEDOUT;
+        next = ctx->next;
+
+        ctx->handler(ctx);
+
+        ctx = next;
+    } while (ctx);
 }
 
 



More information about the nginx-devel mailing list