[dev] possible "bug" in ngx_http_read_discarded_body_handler

Igor Sysoev is at rambler-co.ru
Wed Oct 3 19:16:29 MSD 2007


On Wed, Oct 03, 2007 at 05:11:53PM +0200, Manlio Perillo wrote:

> Igor Sysoev ha scritto:
> >On Mon, Oct 01, 2007 at 08:46:56PM +0200, Manlio Perillo wrote:
> >
> >>I'm reading the ngx_http_request_body source file version 0.5.31, and I 
> >>have found a possible "bug":
> >>
> >>
> >>static void
> >>ngx_http_read_discarded_body_handler(ngx_http_request_t *r)
> >>{
> >>    ngx_int_t  rc;
> >>
> >>    rc = ngx_http_read_discarded_body(r);
> >>
> >>    if (rc == NGX_AGAIN) {
> >>        if (ngx_handle_read_event(r->connection->read, 0) == NGX_ERROR) 
> >>   {
> >>            ngx_http_finalize_request(r, rc);
> >>            return;
> >>        }
> >>    }
> >>
> >>
> >>I think that the code should be:
> >>
> >>    if (rc == NGX_AGAIN) {
> >>        if (ngx_handle_read_event(r->connection->read, 0) == NGX_ERROR) 
> >>   {
> >>            ngx_http_finalize_request(r, NGX_ERROR);
> >>            return;
> >>        }
> >>    }
> >>
> >>
> >>If I'm wrong, then I do not understand why to finalize with NGX_AGAIN.
> >
> >Yes, you right. Fortunatly, ngx_handle_read_event() should never fail,
> >only if something wrong in kernel.
> >
> 
> I have read the ngx_http_finalize_request source and it handles the 
> NGX_AGAIN status code.

If request was finished with NGX_AGAIN and there is buffered data in
filters, then nginx set ngx_http_writer() that pumps this data to client.

> Its very hard to follow the entire code flow of Nginx!

It is even more complex if you look subreqeust processing.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list