# Strange prepending of 0 to response

**URL:** <https://www.ruby-forum.com/t/strange-prepending-of-0-to-response/202551>\
**Category:** NGINX\
**Created:** [February 1, 2011, 11:16am UTC](https://www.ruby-forum.com/t/strange-prepending-of-0-to-response/202551 "2011-02-01T11:16:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 1, 2011, 11:16am UTC](https://www.ruby-forum.com/t/strange-prepending-of-0-to-response/202551/1 "2011-02-01T11:16:00Z")

</div>

Hi All,

Sorry that my first posting here is a support request/bug report, but  
I’ve gotta start somewhere!

So - basically, we’re seeing responses occasionally (not always - in  
fact, quite infrequently) coming back with a 0 prepended to the entire  
response - before the headers.

This means that the response received by the browser ends up looking  
like

* * *

0

HTTP/1.1 200 OK  
Server: nginx/0.8.53  
Date: Tue, 01 Feb 2011 09:07:27 GMT  
Content-Type: text/html; charset=utf-8  
Transfer-Encoding: chunked  
Connection: keep-alive  
Set-Cookie: blu-session-id=2baf936adc11f79aad72827d46fd31aa; path=/;  
HttpOnly  
Expires: Mon, 1 Jan 2001 00:00:00 GMT  
Last-Modified: Tue, 01 Feb 2011 09:07:27 GMT  
Cache-Control: no-store, no-cache, must-revalidate, max-age=0,  
post-check=0, pre-check=0  
Pragma: no-cache  
p3p: CP=“IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND  
CNT”  
Content-Encoding: gzip

and then a load of gzip’d data.

* * *

This of course breaks all sorts of behaviour. We initially thought it  
was coming from HttpProxyModule, however after reconfiguring to serve  
certain assets directly from disk, rather than via the proxy, we saw the  
same issue repeating itself, meaning that it’s probably independent from  
the proxy module.

Has anyone seen this behaviour before? Any ideas on where it’s coming  
from?

Thanks in advance!

Maxwell

---

<div class="post-metadata">

**Author:** ![Maxwell\_Lamb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@Maxwell\_Lamb](https://www.ruby-forum.com/u/Maxwell_Lamb)\
**Post date:** [February 1, 2011, 12:27pm UTC](https://www.ruby-forum.com/t/strange-prepending-of-0-to-response/202551/2 "2011-02-01T12:27:38Z")

</div>

You’re absolutely correct - I’ve just applied the patch, rebuilt, run  
through a few million requests, and it’s no longer happening.

Thanks so much!

Maxwell

---

<div class="post-metadata">

**Author:** ![Maxwell\_Lamb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@Maxwell\_Lamb](https://www.ruby-forum.com/u/Maxwell_Lamb)\
**Post date:** [February 1, 2011, 11:52am UTC](https://www.ruby-forum.com/t/strange-prepending-of-0-to-response/202551/3 "2011-02-01T11:52:27Z")

</div>

Hello!

On Tue, Feb 01, 2011 at 10:14:19AM +0000, Maxwell Lamb wrote:

> looking like  
> Set-Cookie: blu-session-id=2baf936adc11f79aad72827d46fd31aa; path=/; HttpOnly  
> This of course breaks all sorts of behaviour. We initially  
> thought it was coming from HttpProxyModule, however after  
> reconfiguring to serve certain assets directly from disk, rather  
> than via the proxy, we saw the same issue repeating itself,  
> meaning that it’s probably independent from the proxy module.
> 
> Has anyone seen this behaviour before? Any ideas on where it’s  
> coming from?

This looks like duplicate last chunk (“0” CRLF CRLF) in previous  
request. There is at least one known problem with proxy\_cache  
(with proxy\_cache\_use\_stale) which results in such behaviour.

If you use proxy\_cache you may test if switching it off (or at  
least disabling proxy\_cache\_use\_stale completely) resolves the  
problem. Alternatively, apply patch from here:

> **[\[PATCH 2 of 2\] Cache: fix sending of stale responses](http://mailman.nginx.org/pipermail/nginx-devel/2010-January/000102.html)**

Maxim D.
