[PATCH] NGX_HTTP_SYNC flag in ngx_http_send_special

Manlio Perillo manlio.perillo at gmail.com
Sun May 6 19:22:59 UTC 2012

Hash: SHA1

Il 06/05/2012 20:40, Maxim Dounin ha scritto:
> 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.
> [...]
> 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.

Well, I do not really abort the request; I simply call
ngx_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR).

> 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.

I finally fixed an issue that prevented ngx_http_wsgi_module to be
compiled with "recent" Nginx versions (new request->main->count
introduced in Nginx 0.8.11).

Using 1.2.0 the issue is solved.
Now Nginx returns a correct chunk encoded response, with the special
HTML text for 500 status code at the end of the response body.

It is not required to call ngx_http_send_special(r, NGX_HTTP_FLUSH).

>> 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.

With Nginx 0.7.59 setting sync = 1 cause response body to be truncated.
Buffers sent after sync are not received by the client.

Well, it is no more a problem now that I can use a recent version of Nginx.

Thanks  Manlio
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/


More information about the nginx-devel mailing list