# (bug?)Timeout when proxy-pass 0 byte file

**URL:** <https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361>\
**Category:** NGINX\
**Created:** [September 29, 2009, 4:38pm UTC](https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361 "2009-09-29T16:38:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 29, 2009, 4:38pm UTC](https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361/1 "2009-09-29T16:38:53Z")

</div>

I been expirencing very slow page load when use nginx as frontend(with  
proxy\_pass) for a while.

After some test and debug, i found that it always timeout on response  
of 0 byte file.

So i think there might be a bug when nginx running on proxy mode and  
serving 0 byte files. The frontend will consider there should be more  
data and wait until timeout or something like this.

Btw. Nginx is great. Thanks

tomasen

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 29, 2009, 4:54pm UTC](https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361/2 "2009-09-29T16:54:07Z")

</div>

Hello!

On Tue, Sep 29, 2009 at 10:08:51PM +0800, tOmasEn wrote:

> I been expirencing very slow page load when use nginx as frontend(with  
> proxy\_pass) for a while.
> 
> After some test and debug, i found that it always timeout on response  
> of 0 byte file.
> 
> So i think there might be a bug when nginx running on proxy mode and  
> serving 0 byte files. The frontend will consider there should be more  
> data and wait until timeout or something like this.

Could you please provide nginx -V output and debug log?

Maxim D.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 30, 2009, 5:40am UTC](https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361/3 "2009-09-30T05:40:32Z")

</div>

here is my conf

http{  
…  
proxy\_buffer\_size 4k;  
proxy\_buffers 1024 4k;  
proxy\_temp\_path /data/nginx/proxy\_temp ;  
proxy\_cache\_path /data/nginx/proxy\_cache levels=1:2  
keys\_zone=cache1:1000m;  
…  
server{  
…  
location ~\* .(ico|css|js|gif|jp?g|png|xsl)$ {  
proxy\_set\_header X-Forwarded-For  
$proxy\_add\_x\_forwarded\_for;  
proxy\_set\_header Host $http\_host;  
proxy\_redirect off;  
proxy\_pass [http://61.129.66.75:80](http://61.129.66.75:80);  
proxy\_cache\_key shtatic$request\_uri;  
proxy\_cache cache1;  
break;  
}  
…  
}

the initiall request when there isn’t and cache, everything is ok. the  
following request to same url will wait until timeout.

this is the debug log around the second request:

2009/09/30 10:53:57 [debug] 6733#0: event timer del: -1: 1254279237061  
2009/09/30 10:53:57 [debug] 6733#0: http file cache expire  
2009/09/30 10:53:57 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:53:57 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:53:57 [debug] 6733#0: event timer add: -1:  
10000:1254279247061  
2009/09/30 10:53:57 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:53:57 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:54:07 [debug] 6733#0: timer delta: 10000  
2009/09/30 10:54:07 [debug] 6733#0: event timer del: -1: 1254279247061  
2009/09/30 10:54:07 [debug] 6733#0: http file cache expire  
2009/09/30 10:54:07 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:54:07 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:54:07 [debug] 6733#0: event timer add: -1:  
10000:1254279257061  
2009/09/30 10:54:07 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:54:07 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:54:15 [debug] 6732#0: timer delta: 38923  
2009/09/30 10:54:15 [debug] 6732#0: posted events 0000000000000000  
2009/09/30 10:54:15 [debug] 6732#0: worker cycle  
2009/09/30 10:54:15 [debug] 6732#0: epoll timer: 1  
2009/09/30 10:54:15 [debug] 6732#0: timer delta: 4  
2009/09/30 10:54:15 [debug] 6732#0: \*4 event timer del: 13:  
1254279255991  
2009/09/30 10:54:15 [debug] 6732#0: \*4 http keepalive handler  
2009/09/30 10:54:15 [debug] 6732#0: \*4 close http connection: 13  
2009/09/30 10:54:15 [debug] 6732#0: \*4 free: 000000000BC58070  
2009/09/30 10:54:15 [debug] 6732#0: \*4 free: 0000000000000000  
2009/09/30 10:54:15 [debug] 6732#0: \*4 free: 000000000BB9B890, unused: 8  
2009/09/30 10:54:15 [debug] 6732#0: \*4 free: 000000000BB9BAE0, unused:  
128  
2009/09/30 10:54:15 [debug] 6732#0: posted events 0000000000000000  
2009/09/30 10:54:15 [debug] 6732#0: worker cycle  
2009/09/30 10:54:15 [debug] 6732#0: epoll timer: -1  
2009/09/30 10:54:17 [debug] 6733#0: timer delta: 10001  
2009/09/30 10:54:17 [debug] 6733#0: event timer del: -1: 1254279257061  
2009/09/30 10:54:17 [debug] 6733#0: http file cache expire  
2009/09/30 10:54:17 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:54:17 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:54:17 [debug] 6733#0: event timer add: -1:  
10000:1254279267063  
2009/09/30 10:54:17 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:54:17 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:54:27 [debug] 6733#0: timer delta: 10000  
2009/09/30 10:54:27 [debug] 6733#0: event timer del: -1: 1254279267063  
2009/09/30 10:54:27 [debug] 6733#0: http file cache expire  
2009/09/30 10:54:27 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:54:27 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:54:27 [debug] 6733#0: event timer add: -1:  
10000:1254279277063  
2009/09/30 10:54:27 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:54:27 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:54:37 [debug] 6733#0: timer delta: 10001  
2009/09/30 10:54:37 [debug] 6733#0: event timer del: -1: 1254279277063  
2009/09/30 10:54:37 [debug] 6733#0: http file cache expire  
2009/09/30 10:54:37 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:54:37 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:54:37 [debug] 6733#0: event timer add: -1:  
10000:1254279287064  
2009/09/30 10:54:37 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:54:37 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:54:47 [debug] 6733#0: timer delta: 10000  
2009/09/30 10:54:47 [debug] 6733#0: event timer del: -1: 1254279287064  
2009/09/30 10:54:47 [debug] 6733#0: http file cache expire  
2009/09/30 10:54:47 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:54:47 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:54:47 [debug] 6733#0: event timer add: -1:  
10000:1254279297064  
2009/09/30 10:54:47 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:54:47 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:54:57 [debug] 6733#0: timer delta: 10000  
2009/09/30 10:54:57 [debug] 6733#0: event timer del: -1: 1254279297064  
2009/09/30 10:54:57 [debug] 6733#0: http file cache expire  
2009/09/30 10:54:57 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:54:57 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:54:57 [debug] 6733#0: event timer add: -1:  
10000:1254279307064  
2009/09/30 10:54:57 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:54:57 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:55:07 [debug] 6733#0: timer delta: 10002  
2009/09/30 10:55:07 [debug] 6733#0: event timer del: -1: 1254279307064  
2009/09/30 10:55:07 [debug] 6733#0: http file cache expire  
2009/09/30 10:55:07 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:55:07 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:55:07 [debug] 6733#0: event timer add: -1:  
10000:1254279317066  
2009/09/30 10:55:07 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:55:07 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:55:17 [debug] 6733#0: timer delta: 10000  
2009/09/30 10:55:17 [debug] 6733#0: event timer del: -1: 1254279317066  
2009/09/30 10:55:17 [debug] 6733#0: http file cache expire  
2009/09/30 10:55:17 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:55:17 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:55:17 [debug] 6733#0: event timer add: -1:  
10000:1254279327066  
2009/09/30 10:55:17 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:55:17 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:55:27 [debug] 6733#0: timer delta: 10001  
2009/09/30 10:55:27 [debug] 6733#0: event timer del: -1: 1254279327066  
2009/09/30 10:55:27 [debug] 6733#0: http file cache expire  
2009/09/30 10:55:27 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:55:27 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:55:27 [debug] 6733#0: event timer add: -1:  
10000:1254279337067  
2009/09/30 10:55:27 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:55:27 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:55:37 [debug] 6733#0: timer delta: 10000  
2009/09/30 10:55:37 [debug] 6733#0: event timer del: -1: 1254279337067  
2009/09/30 10:55:37 [debug] 6733#0: http file cache expire  
2009/09/30 10:55:37 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:55:37 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:55:37 [debug] 6733#0: event timer add: -1:  
10000:1254279347067  
2009/09/30 10:55:37 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:55:37 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:55:47 [debug] 6733#0: timer delta: 10001  
2009/09/30 10:55:47 [debug] 6733#0: event timer del: -1: 1254279347067  
2009/09/30 10:55:47 [debug] 6733#0: http file cache expire  
2009/09/30 10:55:47 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:55:47 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:55:47 [debug] 6733#0: event timer add: -1:  
10000:1254279357068  
2009/09/30 10:55:47 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:55:47 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:55:57 [debug] 6733#0: timer delta: 10001  
2009/09/30 10:55:57 [debug] 6733#0: event timer del: -1: 1254279357068  
2009/09/30 10:55:57 [debug] 6733#0: http file cache expire  
2009/09/30 10:55:57 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:55:57 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:55:57 [debug] 6733#0: event timer add: -1:  
10000:1254279367069  
2009/09/30 10:55:57 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:55:57 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:56:07 [debug] 6733#0: timer delta: 10000  
2009/09/30 10:56:07 [debug] 6733#0: event timer del: -1: 1254279367069  
2009/09/30 10:56:07 [debug] 6733#0: http file cache expire  
2009/09/30 10:56:07 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:56:07 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:56:07 [debug] 6733#0: event timer add: -1:  
10000:1254279377069  
2009/09/30 10:56:07 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:56:07 [debug] 6733#0: epoll timer: 10000  
2009/09/30 10:56:17 [debug] 6733#0: timer delta: 10001  
2009/09/30 10:56:17 [debug] 6733#0: event timer del: -1: 1254279377069  
2009/09/30 10:56:17 [debug] 6733#0: http file cache expire  
2009/09/30 10:56:17 [debug] 6733#0: malloc: 000000000BB9B890:62  
2009/09/30 10:56:17 [debug] 6733#0: http file cache size: 1  
2009/09/30 10:56:17 [debug] 6733#0: event timer add: -1:  
10000:1254279387070  
2009/09/30 10:56:17 [debug] 6733#0: posted events 0000000000000000  
2009/09/30 10:56:17 [debug] 6733#0: epoll timer: 10000

and -V output:  
–with-http\_ssl\_module --with-md5-asm --with-sha1-asm  
–with-http\_xslt\_module --add-module=/home/nginx\_uploadprogress\_module  
–with-debug

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 30, 2009, 8:54pm UTC](https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361/4 "2009-09-30T20:54:30Z")

</div>

Hello!

On Wed, Sep 30, 2009 at 12:42:52PM +0400, Maxim D. wrote:

> On Wed, Sep 30, 2009 at 11:26:59AM +0800, tOmasEn wrote:

[…]

> > the initiall request when there isn’t and cache, everything is ok. the  
> > following request to same url will wait until timeout.
> 
> Ok, so the problem is cache. Thanks, I’m able to reproduce it  
> here. I’ll take a look later today how to fix it.

Patch.

Maxim D.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 1, 2009, 11:37pm UTC](https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361/5 "2009-10-01T23:37:57Z")

</div>

Hello!

On Wed, Sep 30, 2009 at 10:48:27PM +0400, Maxim D. wrote:

> > Ok, so the problem is cache. Thanks, I’m able to reproduce it  
> > here. I’ll take a look later today how to fix it.
> 
> Patch.

No, this patch is wrong. Corrected patch attached.

Maxim D.

> > > > > So i think there might be a bug when nginx running on proxy mode and  
> > > > > tomasen
> > > > > 
> > > > > –  
> > > > > ä»Žæˆ‘çš„ç§»åŠ¨è®¾å¤‡å‘é€

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 30, 2009, 10:50am UTC](https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361/6 "2009-09-30T10:50:14Z")

</div>

Hello!

On Wed, Sep 30, 2009 at 11:26:59AM +0800, tOmasEn wrote:

> server{  
> …  
> }
> 
> the initiall request when there isn’t and cache, everything is ok. the  
> following request to same url will wait until timeout.

Ok, so the problem is cache. Thanks, I’m able to reproduce it  
here. I’ll take a look later today how to fix it.

Maxim D.

[…]

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [October 2, 2009, 4:45pm UTC](https://www.ruby-forum.com/t/bug-timeout-when-proxy-pass-0-byte-file/176361/7 "2009-10-02T16:45:20Z")

</div>

Hello!

On Fri, Oct 02, 2009 at 01:29:56AM +0400, Maxim D. wrote:

> > […]
> > 
> > > > the initiall request when there isn’t and cache, everything is ok. the  
> > > > following request to same url will wait until timeout.
> > > 
> > > Ok, so the problem is cache. Thanks, I’m able to reproduce it  
> > > here. I’ll take a look later today how to fix it.
> > 
> > Patch.
> 
> No, this patch is wrong. Corrected patch attached.

No, this patch is wrong too as it will trigger “[alert] … zero  
size buf in output” messages in error log for empty cached  
subrequests. Corrected patch attached.

Maxim D.

> > > > > > After some test and debug, i found that it always timeout on response
> 
> > @@ -798,7 +798,7 @@ ngx\_http\_cache\_send(ngx\_http\_request\_t \*
> > 
> > ```
> > size = c->length - c->body_start;
> > if (size == 0) {
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > return rc;
> > 
> > ```
> > 
> > - 
> > 
> > ```
> > return ngx_http_send_special(r, NGX_HTTP_LAST);
> > 
> > ```
> > 
> > }
> > 
> > b-\>file\_pos = c-\>body\_start;
