NGX_AGAIN and POST data

Brian Bruns brian.bruns at gmail.com
Mon Oct 6 19:05:28 MSD 2008


Yes that is basically what I'm doing:

rc = ngx_http_read_client_request_body(r, my_handler);

if (rc != NGX_OK) {
   ngx_log_error( ... );
   return rc;
}

I see the message in the log, so I know I returned from here with
NGX_AGAIN, but the request_body_handler never gets invoked.  Is there
some state I should be setting on the ngx_http_request_t before
returning control?

Thanks again for your help,

Brian

2008/10/6 Valery Kholodkov <valery+nginxen at grid.net.ru>:
>
> Hey, sorry for confusing you. What I do in this case is:
>
> static ngx_int_t some_handler(ngx_http_request_t *r)
> {
>
>   [ ...blah... ]
>
>    rc = ngx_http_read_client_request_body(r, my_handler);
>
>    if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
>        return rc;
>    }
>
>    return NGX_DONE;
> }
>
> So, basically I check the return value of
> ngx_http_read_client_request_body and if it is weird, simply return it,
> otherwise always return NGX_DONE.
>
>> Using urllib, which causes the NGX_AGAIN return, I get the following
>> in the log (the first statement is mine after the call to
>> ngx_http_read_client_request_body prior to returning NGX_AGAIN to the
>> caller).
>>
>> 2008/10/06 07:23:37 [alert] 34159#0: *5 failed to read client request
>> body, client: 192.168.16.1, server: localhost, request: "POST /sql
>> HTTP/1.0", host: "192.168.16.1:8081"
>> 2008/10/06 07:23:37 [debug] 34159#0: *5 http finalize request: -2, "/sql?"
>> 2008/10/06 07:23:37 [debug] 34159#0: *5 event timer add: 6:
>> 60000:3525165053
>> 2008/10/06 07:23:37 [debug] 34159#0: timer delta: 1
>> 2008/10/06 07:23:37 [debug] 34159#0: posted events 00000000
>> 2008/10/06 07:23:37 [debug] 34159#0: worker cycle
>> 2008/10/06 07:23:37 [debug] 34159#0: kevent timer: 60000, changes: 0
>> 2008/10/06 07:23:37 [debug] 34159#0: kevent events: 1
>> 2008/10/06 07:23:37 [debug] 34159#0: kevent: 6: ft:-1 fl:0025
>> ff:00000000 d:84 ud:002280B5
>> 2008/10/06 07:23:37 [debug] 34159#0: *5 http test reading
>> 2008/10/06 07:23:37 [debug] 34159#0: timer delta: 1
>> 2008/10/06 07:23:37 [debug] 34159#0: posted events 00000000
>> 2008/10/06 07:23:37 [debug] 34159#0: worker cycle
>> 2008/10/06 07:23:37 [debug] 34159#0: kevent timer: 59999, changes: 0
>>
>>
>> My request_body_handler never gets called and the client eventually times
>> out.
>>
>> Thanks again,
>>
>> Brian
>>
>> 2008/10/6 Valery Kholodkov <valery+nginxen at grid.net.ru>:
>>>
>>>> The confusing part to me is the following lines from
>>>> src/http/ngx_http_core_module.c:
>>>>
>>>>     if (r->content_handler) {
>>>>         r->write_event_handler = ngx_http_request_empty_handler;
>>>>         ngx_http_finalize_request(r, r->content_handler(r));
>>>>         return NGX_OK;
>>>>     }
>>>>
>>>> which appears to (according the debug stuff in the log) simply close
>>>> out the connection regardless of the return value from
>>>> content_handler().  Shouldn't my module be getting re-called when more
>>>> data is available from the connection or am I misunderstanding
>>>> something?
>>>
>>> No. post_handler (the second argument of
>>> ngx_http_read_client_request_body) should be called when the body will
>>> be
>>> successfully received.
>>>
>>> ngx_http_finalize_request does not close the connection whenever rc ==
>>> NGX_AGAIN. Instead ngx_http_read_client_request_body sets read handler
>>> to
>>> ngx_http_read_client_request_body_handler. Therefore the read handler
>>> will
>>> be recalled, not your handler.
>
> --
> Best regards,
> Valery Kholodkov
>
>
>





More information about the nginx mailing list