comparison src/http/ngx_http_upstream.c @ 5157:d6980725e25c stable-1.2

Merge of r5113, r5114: upstream: resolve errors handling. Upstream: call ngx_http_run_posted_requests() on resolve errors. If proxy_pass to a host with dynamic resolution was used to handle a subrequest, and host resolution failed, the main request wasn't run till something else happened on the connection. E.g. request to "/zzz" with the following configuration hanged: addition_types *; resolver 8.8.8.8; location /test { set $ihost xxx; proxy_pass http://$ihost; } location /zzz { add_after_body /test; return 200 "test"; } Report and original version of the patch by Lanshun Zhou, http://mailman.nginx.org/pipermail/nginx-devel/2013-March/003476.html.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 29 Mar 2013 17:34:45 +0000
parents be9ce2946a8e
children ee9a043765ea
comparison
equal deleted inserted replaced
5156:306fb0cc0fba 5157:d6980725e25c
863 863
864 864
865 static void 865 static void
866 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx) 866 ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)
867 { 867 {
868 ngx_connection_t *c;
868 ngx_http_request_t *r; 869 ngx_http_request_t *r;
869 ngx_http_upstream_t *u; 870 ngx_http_upstream_t *u;
870 ngx_http_upstream_resolved_t *ur; 871 ngx_http_upstream_resolved_t *ur;
871 872
872 r = ctx->data; 873 r = ctx->data;
874 c = r->connection;
873 875
874 u = r->upstream; 876 u = r->upstream;
875 ur = u->resolved; 877 ur = u->resolved;
876 878
877 if (ctx->state) { 879 if (ctx->state) {
879 "%V could not be resolved (%i: %s)", 881 "%V could not be resolved (%i: %s)",
880 &ctx->name, ctx->state, 882 &ctx->name, ctx->state,
881 ngx_resolver_strerror(ctx->state)); 883 ngx_resolver_strerror(ctx->state));
882 884
883 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY); 885 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
884 return; 886 goto failed;
885 } 887 }
886 888
887 ur->naddrs = ctx->naddrs; 889 ur->naddrs = ctx->naddrs;
888 ur->addrs = ctx->addrs; 890 ur->addrs = ctx->addrs;
889 891
904 #endif 906 #endif
905 907
906 if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) { 908 if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) {
907 ngx_http_upstream_finalize_request(r, u, 909 ngx_http_upstream_finalize_request(r, u,
908 NGX_HTTP_INTERNAL_SERVER_ERROR); 910 NGX_HTTP_INTERNAL_SERVER_ERROR);
909 return; 911 goto failed;
910 } 912 }
911 913
912 ngx_resolve_name_done(ctx); 914 ngx_resolve_name_done(ctx);
913 ur->ctx = NULL; 915 ur->ctx = NULL;
914 916
915 ngx_http_upstream_connect(r, u); 917 ngx_http_upstream_connect(r, u);
918
919 failed:
920
921 ngx_http_run_posted_requests(c);
916 } 922 }
917 923
918 924
919 static void 925 static void
920 ngx_http_upstream_handler(ngx_event_t *ev) 926 ngx_http_upstream_handler(ngx_event_t *ev)