How to handle NGX_AGAIN returned by ngx_http_read_client_request_body() within handler module?
mdounin at mdounin.ru
Tue Jun 30 03:21:03 MSD 2009
On Mon, Jun 29, 2009 at 06:33:27PM -0400, sayeo87 wrote:
> I am trying to develop a handler module in Nginx 0.7.59 to intercept POST requests and perform internal redirections based on the values in the POST data. The problem is, on larger POST requests (~ > 2KB), ngx_http_read_client_request_body() sometimes returns NGX_AGAIN instead of NGX_OK. I have read at various places that if one receives any other status than NGX_OK that that the module should immediately return that status. I have also read that after getting and returning NGX_AGAIN, NGINX will call your module again after other pending network activity. However, I have tried doing this but my module never gets called again.
General recomendation is: read code instead of "various places".
Expected module behaviour depend highly on exact place where it's used.
For this particular case try reading what other
ngx_http_read_client_request_body() callers do, e.g.
ngx_http_proxy_module. I believe it's clear enough. And the code
behind ngx_http_read_client_request_body() itself also deserves
some reading if you want to understand how it works.
> What I have resorted to is to perform another ngx_http_read_client_request_body() call if I get an NGX_AGAIN. At least within the module this seems to work, but whenever I have to do this the resulting request to the upstream server always times out. But when I don't get NGX_AGAIN, everything is perfectly fine.
Calling ngx_http_read_client_request_body() again won't do
anything good. As you can see from first several lines of this
function - it will just call completion handler when called again.
> How should I handle these cases where ngx_http_read_client_request_body() returns NGX_AGAIN?
> Thanks in advance!
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,3545,3545#msg-3545
More information about the nginx