[PATCH] NGX_HTTP_SYNC flag in ngx_http_send_special

Maxim Dounin mdounin at mdounin.ru
Sun May 6 18:40:10 UTC 2012


Hello!

On Fri, May 04, 2012 at 07:52:33PM +0200, Manlio Perillo wrote:

> Patch is attached, against mercurial mirror changeset 47cb3497fbab.
> 
> 
> Use case:
> 
> I'm updating my ngx_http_wsgi_module.
> 
> In one of my test application, I return a chunk-encoded response.
> The problem is that after last buffer is sent, I raise an exception,
> causing Nginx to abort the request handling.
> 
> This, in turn, cause an incorrect chunk encoding (Python httplib fails
> to read the response).
> 
> Calling
>   ngx_http_send_special(r, NGX_HTTP_FLUSH)
> after last buffer does not help, however I found that using my patch,
> calling
>   ngx_http_send_special(r, NGX_HTTP_FLUSH | NGX_HTTP_SYNC)
> do help; now the response is correctly chunk encoded.
>
> Please note that I tested my patch using 0.7.59, since
> ngx_http_wsgi_module has some issues on recent Nginx versions (that I'm
> going to fix).

Just ngx_http_send_special(r, NGX_HTTP_FLUSH) should be enough to 
flush internal buffers, but please not that it doesn't mean that 
response is actually sent - there still may be buffering on socket 
level etc.  If you abort request handling (not sure how you do it) 
- it may result in incomplete response sent.

Not sure about 0.7.59, it's really old, but if you'll still see 
the problem with 1.2.0 - please report more details, we probably 
want to fix this properly.

> Also note that I can not use NGX_HTTP_LAST (due to how
> ngx_http_wsgi_module is implemented), and I'm not sure if is it correct
> to set sync = 1 for a buffer that is not the last one.

Setting sync = 1 on intermediate buffers is ok, but it shouldn't 
be needed to explicitly sent such buffers.

Maxim Dounin



More information about the nginx-devel mailing list