Skip to content

Commit

Permalink
Upstream: fixed running posted requests (ticket #788).
Browse files Browse the repository at this point in the history
Previously, the upstream resolve handler always called
ngx_http_run_posted_requests() to run posted requests after processing the
resolver response.  However, if the handler was called directly from the
ngx_resolve_name() function (for example, if the resolver response was cached),
running posted requests from the handler could lead to the following errors:

- If the request was scheduled for termination, it could actually be terminated
in the resolve handler.  Upper stack frames could reference the freed request
object in this case.

- If a significant number of requests were posted, and for each of them the
resolve handler was called directly from the ngx_resolve_name() function,
posted requests could be run recursively and lead to stack overflow.

Now ngx_http_run_posted_requests() is only called from asynchronously invoked
resolve handlers.
  • Loading branch information
arut committed Jun 14, 2017
1 parent 439e205 commit efa61f4
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/http/ngx_http_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1143,11 +1143,14 @@ ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
static void
ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)
{
ngx_uint_t run_posted;
ngx_connection_t *c;
ngx_http_request_t *r;
ngx_http_upstream_t *u;
ngx_http_upstream_resolved_t *ur;

run_posted = ctx->async;

r = ctx->data;
c = r->connection;

Expand Down Expand Up @@ -1211,7 +1214,9 @@ ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)

failed:

ngx_http_run_posted_requests(c);
if (run_posted) {
ngx_http_run_posted_requests(c);
}
}


Expand Down

0 comments on commit efa61f4

Please sign in to comment.