Re: ngx_http_request_t's subrequests is what meaning be?

Maxim Dounin mdounin at mdounin.ru
Thu Jul 1 18:08:03 MSD 2010


Hello!

On Thu, Jul 01, 2010 at 08:08:42PM +0800, BoBo wrote:

> hi all.
> 
> I am reading  nginx's source(version is 0.7.66), but i don't understand this
> section:
> 
> ngx_int_t
> ngx_http_subrequest(ngx_http_request_t *r,
>     ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
>     ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
> {
>     ngx_connection_t              *c;
>     ngx_http_request_t            *sr;
>     ngx_http_core_srv_conf_t      *cscf;
>     ngx_http_postponed_request_t  *pr, *p;
> 
> //i know subrequests's default is NGX_HTTP_MAX_SUBREQUESTS + 1 = 51;
>     r->main->subrequests--;
> 
> //when subrequests is  0?
>     if (r->main->subrequests == 0) {
>         ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
>                       "subrequests cycle while processing \"%V\"", uri);
>         r->main->subrequests = 1;
>         return NGX_ERROR;
>     }
> ....................................................................
> 
> //why subrequests need plus plus?
>     r->main->subrequests++;
> 
>     *psr = sr;
> 
>     return ngx_http_post_request(sr);
> }
> 
> the problem is after call ngx_http_subrequest and  r->main->subrequests will
> not change(because subrequests-- and then ++), so when subrequests is  0?

Right now - it would never be 0 (and this strikes badly as long as 
you issue > 255 subrequests, as r->main->counter overflows).  This 
logic was introduced for older subrequest implementation where 
subrequests were completed directly.  Subrequest processing was 
changed in 0.7.25 and this subrequests-- and subrequests++ no 
longer make sense.

I've posted a patch a while ago which moves r->main->subrequests++ 
into request finalization, see here (in Russian):

http://nginx.org/pipermail/nginx-ru/2010-February/032184.html

Maxim Dounin



More information about the nginx mailing list