handle NGX_AGAIN properly

Julien Zefi jzefip at gmail.com
Mon Jul 15 03:43:43 UTC 2013


Hi,


On Sun, Jul 14, 2013 at 12:40 AM, Yichun Zhang (agentzh)
<agentzh at gmail.com>wrote:

> Hello!
>
> On Sat, Jul 13, 2013 at 4:43 PM, Julien Zefi wrote:
> >
> > I have been trying many workarounds without luck, the last one that i
> have
> > is that if in my timer-callback the flush returns NGX_AGAIN, invoke a new
> > handler that sends out an empty chain, but it continue returning
> NGX_AGAIN,
> > it never backs to NGX_OK, this is how it looks:
> >
>
> It seems that what you're doing is very wrong. You'd better take a
> look at how the ngx_http_writer and ngx_http_set_write_handler
> functions are implemented in the Nginx core instead of shooting in the
> darkness. Basically:
>
> 1. Flush outputs by r->write_event_handler instead of in your timer
> handler because you should only retry sending the outputs upon a
> epoll/poll/select write event.
>
> 2. By "sending out an empty chain", I actually mean
>
>     rc = ngx_http_output_filter(r, NULL);
>
> You can see this line in the ngx_http_writer function. You're just
> sending out a last_buf chain.
>
>
Sorry by bother you again but i still cannot figure out how some internals
are not working as i expect. I have take in count your suggestions and
wrote a new test case (file attached).

My goal in that test case is to let NginX invoke my write_event_handler
once the socket is ready to write again when a NGX_AGAIN is found, despite
the test case is not perfect for all things that need to be fixed, i have
isolated as much as i can.

The test case writes 12.3KB of data every 1ms, at some point it will raise
NGX_AGAIN but from there is not recovering, it keeps in the same state
forever, do you see any specific problem when handling the exception ?

thnks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20130714/618e1361/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_case_02.tar.gz
Type: application/x-gzip
Size: 1372 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20130714/618e1361/attachment.bin>


More information about the nginx-devel mailing list