# Sub filterâ€˜s bug?

**URL:** <https://www.ruby-forum.com/t/sub-filtera-s-bug/194993>\
**Category:** NGINX\
**Created:** [September 15, 2010, 5:02am UTC](https://www.ruby-forum.com/t/sub-filtera-s-bug/194993 "2010-09-15T05:02:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [September 15, 2010, 5:02am UTC](https://www.ruby-forum.com/t/sub-filtera-s-bug/194993/1 "2010-09-15T05:02:00Z")

</div>

my nginx version is 0.7.67.

I test nginx’s sub filter, there have some alert log in error log:

_the http output chain is empty while sending response to client._  
\*  
\*  
and i debug nginx , and then found this is cause by sub filter. so i  
read  
sub filter’s source.

in ngx\_http\_sub\_body\_filter:

- if (ctx-\>once && (ctx-\>buf == NULL || ctx-\>in == NULL)) {\*
- 
- 
- 

```
   if (ctx->busy) {*

```

- 

```
       if (ngx_http_sub_output(r, ctx) == NGX_ERROR) {*

```

- 

```
           return NGX_ERROR;*

```

- 

```
       }*

```

- 

```
   }*

```

- 
- 
- 

```
   return ngx_http_next_body_filter(r, in);*

```

- }\*

i found when sub\_filter\_once is on , after text have replaced . and  
the  
second enter ngx\_http\_sub\_body\_filter.  
At the moment when in is null,ctx-\>busy is not null,and so  
_ngx\_http\_sub\_output  
may send the rest of buf completely_\*, therefore in  
\*\*ngx\_http\_next\_body\_filter  
will log alert log : the http output chain is empty while sending  
response  
to client. \*  
\*  
\*  
_i_n conclusion I \*think there should add a \*judgement that in is  
whether  
or not NULL.  
\*  
\*  
_this is my patch:_  
\*  
\*  
\*  
— nginx-0.7.67/src/http/modules/ngx\_http\_sub\_filter\_module.c  
2009-10-26  
23:54:29.000000000 +0800  
+++ nginx-0.7.67\_new/src/http/modules/ngx\_http\_sub\_filter\_module.c  
2010-09-15  
10:14:04.996666685 +0800  
@@ -187,16 +187,16 @@ ngx\_http\_sub\_body\_filter(ngx\_http\_reques  
}

```
 if (ctx->once && (ctx->buf == NULL || ctx->in == NULL)) {

     if (ctx->busy) {

```

- 

```
       if (ngx_http_sub_output(r, ctx) == NGX_ERROR) {

```

- 

```
           return NGX_ERROR;

```

- 

```
       }

```

- 

```
       rc = ngx_http_sub_output(r, ctx);
   }

```

- 

```
   return ngx_http_next_body_filter(r, in);

```

- 

```
   if (rc != NGX_ERROR && in != NULL)

```

- 

```
       return ngx_http_next_body_filter(r, in);

```

- 

```
   return rc;

```

}

/\* add the incoming chain to the chain ctx-\>in \*/

if (in) {

- 
- 
- 

–  
åšè§‚çº¦å–

è±†ç“£:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: [www.twitter.com/minibobo](http://www.twitter.com/minibobo)

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [September 21, 2010, 11:09am UTC](https://www.ruby-forum.com/t/sub-filtera-s-bug/194993/2 "2010-09-21T11:09:08Z")

</div>

i find this result is cause by postpone filter is removed. because i  
use --without-http\_ssi\_module config nginx. and i read nginx config find  
this in auto/modules:

if [$HTTP\_SSI = YES]; then  
HTTP\_POSTPONE=YES  
fi

if [$HTTP\_ADDITION = YES]; then  
HTTP\_POSTPONE=YES  
fi

and why postpone is yes when ssi or addition module is on ?  
and then i debug nginx find some code in ngx\_http\_postpone\_filter method  
:

```
if (r->postponed == NULL) {

    if (in || c->buffered) {
        return ngx_http_next_filter(r->main, in);
    }

    return NGX_OK;
}

```

therefore if no postpone module, sub filter module may emerge the result  
in  
my previous email .

On Wed, Sep 15, 2010 at 11:00 AM, Simon L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> in ngx\_http\_sub\_body\_filter:  
> \*  
> \*  
> +++ nginx-0.7.67\_new/src/http/modules/ngx\_http\_sub\_filter\_module.c 2010-09-15
> 
> - 
> 
> ```
> rc = ngx_http_sub_output(r, ctx);
> 
> ```
> 
> if (in) {  
> twitter: [Minibobo (@minibobo) / X](http://www.twitter.com/minibobo)

–  
åšè§‚çº¦å–

è±†ç“£:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: [Minibobo (@minibobo) / X](http://www.twitter.com/minibobo)

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [September 21, 2010, 1:58pm UTC](https://www.ruby-forum.com/t/sub-filtera-s-bug/194993/3 "2010-09-21T13:58:19Z")

</div>

Hello!

On Tue, Sep 21, 2010 at 05:08:08PM +0800, Simon L. wrote:

> ```
> HTTP_POSTPONE=YES
> 
> ```
> 
> fi
> 
> and why postpone is yes when ssi or addition module is on ?

Postpone filter is used to order data sent by subrequests. It  
shouldn’t be needed when no subrequests are used.

> > - 
> > - 
> > 
> > ```
> > if (ngx_http_sub_output(r, ctx) == NGX_ERROR) {*
> > 
> > ```
> > 
> > At the moment when in is null,ctx-\>busy is not null,and so \*ngx\_http\_sub\_output  
> > \*
> > 
> > - 
> > 
> > ```
> > return rc;
> > 
> > ```

This will use uninitialized rc when no ctx-\>busy.

Maxim D.

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [September 21, 2010, 4:20pm UTC](https://www.ruby-forum.com/t/sub-filtera-s-bug/194993/4 "2010-09-21T16:20:35Z")

</div>

Hello!

On Tue, Sep 21, 2010 at 08:36:11PM +0800, Simon L. wrote:

> if (r-\>postponed == NULL) {
> 
> ```
> if (in || c->buffered) {
> return ngx_http_next_filter(r->main, in);
> }
> 
> return NGX_OK;
> }
> 
> ```
> 
> this code is needed by subrequest only? i think sub filter is needed too.

It is believed that empty chains shouldn’t appear in output. They  
doesn’t make sense unless used to flush various buffers, and  
writer rightfully complains when it sees empty chain while there  
are no buffered data.

The code in postpone filter obviously hides some of “empty chain”  
problems. But it doesn’t mean that sub module needs it. It means  
that sub module have to be fixed (and the problem is usually  
hidden by postpone filter).

Maxim D.

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [September 21, 2010, 2:37pm UTC](https://www.ruby-forum.com/t/sub-filtera-s-bug/194993/5 "2010-09-21T14:37:33Z")

</div>

thanks Maxim!

my patch is mistake.

but when remove http\_ssi\_module , sub filter module may log alert:

“the http output chain is empty while sending response to client.”

because sub filter module need ngx\_http\_postpone\_filter’s code :

if (r-\>postponed == NULL) {

```
    if (in || c->buffered) {
        return ngx_http_next_filter(r->main, in);
    }

    return NGX_OK;
}

```

this code is needed by subrequest only? i think sub filter is needed  
too.

On Tue, Sep 21, 2010 at 7:57 PM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > fi
> 
> > ```
> > }
> > 
> > ```
> > 
> > > I test nginx’s sub filter, there have some alert log in error log:
> > > 
> > > - if (ctx-\>once && (ctx-\>buf == NULL || ctx-\>in == NULL)) {\*
> > > - }\*  
> > > to client. \*
> > > - 
> > > 
> > > - 
> > > 
> > > ```
> > > return rc;
> > > 
> > > ```
> 
> This will use uninitialized rc when no ctx-\>busy.
> 
> Maxim D.
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
åšè§‚çº¦å–

è±†ç“£:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: [Minibobo (@minibobo) / X](http://www.twitter.com/minibobo)

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [September 24, 2010, 5:21am UTC](https://www.ruby-forum.com/t/sub-filtera-s-bug/194993/6 "2010-09-24T05:21:50Z")

</div>

igor will fix this in next version?

On Tue, Sep 21, 2010 at 11:02 PM, Simon L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > > because sub filter module need ngx\_http\_postpone\_filter’s code :  
> > > this code is needed by subrequest only? i think sub filter is needed  
> > > hidden by postpone filter).
> 
> –  
> åšè§‚çº¦å–
> 
> è±†ç“£:www.douban.com/people/mustang/
> 
> blog: www.pagefault.info
> 
> twitter: [Minibobo (@minibobo) / X](http://www.twitter.com/minibobo)

–  
åšè§‚çº¦å–

è±†ç“£:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: [Minibobo (@minibobo) / X](http://www.twitter.com/minibobo)

---

<div class="post-metadata">

**Author:** ![monad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/49beb7/32.png) [@monad](https://www.ruby-forum.com/u/monad)\
**Post date:** [September 21, 2010, 5:04pm UTC](https://www.ruby-forum.com/t/sub-filtera-s-bug/194993/7 "2010-09-21T17:04:29Z")

</div>

thanks maxim!

I agree your perspective , sub filter must deal with this situation(in  
is  
NULL) .

and as you say , this is sub filter’s bug?

On Tue, Sep 21, 2010 at 10:19 PM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > “the http output chain is empty while sending response to client.”  
> > }  
> > problems. But it doesn’t mean that sub module needs it. It means  
> > that sub module have to be fixed (and the problem is usually  
> > hidden by postpone filter).
> 
> Maxim D.
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
åšè§‚çº¦å–

è±†ç“£:www.douban.com/people/mustang/

blog: www.pagefault.info

twitter: [Minibobo (@minibobo) / X](http://www.twitter.com/minibobo)
