pagespeed/ngx_pagespeed — pull request #18 by yaoweibin (2012-11-02 09:55:27+00:00)
Title: fixed the infinite read event loop problem with large output buffer

Here is the problem: all the output work are done by ngx_linux_sendfile_chain() at last. But it's bound to a write event. The write event must be ready. You can see the code like this:

59 if (!wev->ready) {
60 return in;
61 }

At the first time, it's ready. When it output part of the content, it returns NGX_AGAIN. The ready bit is cleared to be 0. All you output work are done in the read handler, you never set the ready bit again. You have read all the data, but can't output any more.

It happens with large file as the linux send buffer is full. Small file rarely returns NGX_AGAIN.

In the normal noblock programming way, when we can't output all the data, we should add a write event to do this.