handle NGX_AGAIN properly

Yichun Zhang (agentzh) agentzh at gmail.com
Sun Jul 14 06:40:15 UTC 2013


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.


More information about the nginx-devel mailing list