comparison src/core/ngx_resolver.c @ 5840:60d2cb03faee stable-1.6

Resolver: notify all waiting requests on timeout. If a "resolver_timeout" occurs, only the first waiting request was notified. Other requests may hang forever.
author Ruslan Ermilov <ru@nginx.com>
date Tue, 19 Aug 2014 15:43:26 +0400
parents 20ebe12cfa7a
children 0395f788b080
comparison
equal deleted inserted replaced
5839:20ebe12cfa7a 5840:60d2cb03faee
415 ngx_del_timer(ctx->event); 415 ngx_del_timer(ctx->event);
416 } 416 }
417 417
418 /* lock name mutex */ 418 /* lock name mutex */
419 419
420 if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) { 420 if (ctx->state == NGX_AGAIN) {
421 421
422 hash = ngx_crc32_short(ctx->name.data, ctx->name.len); 422 hash = ngx_crc32_short(ctx->name.data, ctx->name.len);
423 423
424 rn = ngx_resolver_lookup_name(r, &ctx->name, hash); 424 rn = ngx_resolver_lookup_name(r, &ctx->name, hash);
425 425
662 if (ctx->event == NULL) { 662 if (ctx->event == NULL) {
663 goto failed; 663 goto failed;
664 } 664 }
665 665
666 ctx->event->handler = ngx_resolver_timeout_handler; 666 ctx->event->handler = ngx_resolver_timeout_handler;
667 ctx->event->data = ctx; 667 ctx->event->data = rn;
668 ctx->event->log = r->log; 668 ctx->event->log = r->log;
669 ctx->ident = -1; 669 ctx->ident = -1;
670 670
671 ngx_add_timer(ctx->event, ctx->timeout); 671 ngx_add_timer(ctx->event, ctx->timeout);
672 } 672 }
855 if (ctx->event == NULL) { 855 if (ctx->event == NULL) {
856 goto failed; 856 goto failed;
857 } 857 }
858 858
859 ctx->event->handler = ngx_resolver_timeout_handler; 859 ctx->event->handler = ngx_resolver_timeout_handler;
860 ctx->event->data = ctx; 860 ctx->event->data = rn;
861 ctx->event->log = r->log; 861 ctx->event->log = r->log;
862 ctx->ident = -1; 862 ctx->ident = -1;
863 863
864 ngx_add_timer(ctx->event, ctx->timeout); 864 ngx_add_timer(ctx->event, ctx->timeout);
865 865
947 ngx_del_timer(ctx->event); 947 ngx_del_timer(ctx->event);
948 } 948 }
949 949
950 /* lock addr mutex */ 950 /* lock addr mutex */
951 951
952 if (ctx->state == NGX_AGAIN || ctx->state == NGX_RESOLVE_TIMEDOUT) { 952 if (ctx->state == NGX_AGAIN) {
953 953
954 switch (ctx->addr.sockaddr->sa_family) { 954 switch (ctx->addr.sockaddr->sa_family) {
955 955
956 #if (NGX_HAVE_INET6) 956 #if (NGX_HAVE_INET6)
957 case AF_INET6: 957 case AF_INET6:
2789 2789
2790 2790
2791 static void 2791 static void
2792 ngx_resolver_timeout_handler(ngx_event_t *ev) 2792 ngx_resolver_timeout_handler(ngx_event_t *ev)
2793 { 2793 {
2794 ngx_resolver_ctx_t *ctx; 2794 ngx_resolver_ctx_t *ctx, *next;
2795 2795 ngx_resolver_node_t *rn;
2796 ctx = ev->data; 2796
2797 2797 rn = ev->data;
2798 ctx->state = NGX_RESOLVE_TIMEDOUT; 2798 ctx = rn->waiting;
2799 2799 rn->waiting = NULL;
2800 ctx->handler(ctx); 2800
2801 do {
2802 ctx->state = NGX_RESOLVE_TIMEDOUT;
2803 next = ctx->next;
2804
2805 ctx->handler(ctx);
2806
2807 ctx = next;
2808 } while (ctx);
2801 } 2809 }
2802 2810
2803 2811
2804 static void 2812 static void
2805 ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn) 2813 ngx_resolver_free_node(ngx_resolver_t *r, ngx_resolver_node_t *rn)