<div>my nginx version is 0.7.67.</div><div><br></div><div>I test nginx&#39;s sub filter, there have some alert log in error log:</div><div><br></div><div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" color="#990000">the http output chain is empty while sending response to client.</font></span></i></div>

<div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><br></span></i></div><div><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); ">and  i debug nginx , and then found this is cause by sub filter. so  i read  sub filter&#39;s source. </span></div>

<div><br></div>in  ngx_http_sub_body_filter:<div><br></div><div><div>  <i> <span class="Apple-style-span" style="background-color: rgb(204, 204, 204);"> <span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000">if (ctx-&gt;once &amp;&amp; (ctx-&gt;buf == NULL || ctx-&gt;in == NULL)) {</font></span></span></i></div>

<div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000"><br></font></span></i></div><div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000">        if (ctx-&gt;busy) {</font></span></i></div>

<div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000">            if (ngx_http_sub_output(r, ctx) == NGX_ERROR) {</font></span></i></div><div>
<i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000">                return NGX_ERROR;</font></span></i></div>
<div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000">            }</font></span></i></div><div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000">        }</font></span></i></div>

<div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000"><br></font></span></i></div><div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000">        return ngx_http_next_body_filter(r, in);</font></span></i></div>

<div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255);"><font class="Apple-style-span" color="#FF0000">    }</font></span></i></div><div><br></div><div>i found when  <font class="Apple-style-span" color="#FF0000">sub_filter_once</font> is on , after  text have replaced . and the second enter ngx_http_sub_body_filter.</div>

<div><span class="Apple-style-span" style="line-height: 18px; ">At the moment</span> when <font class="Apple-style-span" color="#FF0000">in</font> is null,<font class="Apple-style-span" color="#FF0000">ctx-&gt;busy</font> is not null,and so <i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" color="#FF0000">ngx_http_sub_output <span class="Apple-style-span" style="font-style: normal;"> <font class="Apple-style-span" color="#000000">may</font></span></font> send  </span></i><span class="Apple-style-span" style="font-family: arial, sans-serif; line-height: 15px; ">the rest of</span><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "> buf  <font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="font-style: normal; ">completely</span></font></span></i><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); ">,  <span class="Apple-style-span" style="font-style: normal; line-height: 18px; ">therefore in </span> </span></i><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><font class="Apple-style-span" color="#FF0000">ngx_http_next_body_filter </font>will log alert log : the http output chain is empty while sending response to client. </span></i></div>

<div><i><br></i></div><div><i>i</i><span class="Apple-style-span" style="line-height: 18px; ">n conclusion I </span><i>think  there should add a </i><span class="Apple-style-span" style="line-height: 18px; ">judgement that<font class="Apple-style-span" color="#FF0000"> in</font> is whether or not NULL.</span></div>

<div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><br></span></i></div><div><i>this is my patch:</i></div><div><i><br></i></div><div><i><div>--- nginx-0.7.67/src/http/modules/ngx_http_sub_filter_module.c<span class="Apple-tab-span" style="white-space:pre">        </span>2009-10-26 23:54:29.000000000 +0800</div>

<div>+++ nginx-0.7.67_new/src/http/modules/ngx_http_sub_filter_module.c<span class="Apple-tab-span" style="white-space:pre">        </span>2010-09-15 10:14:04.996666685 +0800</div><div>@@ -187,16 +187,16 @@ ngx_http_sub_body_filter(ngx_http_reques</div>

<div>     }</div><div> </div><div>     if (ctx-&gt;once &amp;&amp; (ctx-&gt;buf == NULL || ctx-&gt;in == NULL)) {</div><div> </div><div>         if (ctx-&gt;busy) {</div><div>-            if (ngx_http_sub_output(r, ctx) == NGX_ERROR) {</div>

<div>-                return NGX_ERROR;</div><div>-            }</div><div>+            rc = ngx_http_sub_output(r, ctx);</div><div>         }</div><div> </div><div>-        return ngx_http_next_body_filter(r, in);</div>
<div>
+        if (rc != NGX_ERROR &amp;&amp; in != NULL)</div><div>+            return ngx_http_next_body_filter(r, in);</div><div>+        return rc;</div><div>     }</div><div> </div><div>     /* add the incoming chain to the chain ctx-&gt;in */</div>

<div> </div><div>     if (in) {</div></i></div><div><i><span class="Apple-style-span" style="background-color: rgb(255, 255, 255); "><br></span></i></div>-- <br>博观约取<br><br>豆瓣:<a href="http://www.douban.com/people/mustang/" target="_blank">www.douban.com/people/mustang/</a><br>

<br>blog: <a href="http://www.pagefault.info" target="_blank">www.pagefault.info</a><br><br>twitter: <a href="http://www.twitter.com/minibobo" target="_blank">www.twitter.com/minibobo</a><br>
</div>