# Proxy\_cache partial response?

**URL:** <https://www.ruby-forum.com/t/proxy-cache-partial-response/208004>\
**Category:** NGINX\
**Created:** [June 8, 2011, 2:40am UTC](https://www.ruby-forum.com/t/proxy-cache-partial-response/208004 "2011-06-08T02:40:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 8, 2011, 2:40am UTC](https://www.ruby-forum.com/t/proxy-cache-partial-response/208004/1 "2011-06-08T02:40:42Z")

</div>

will nginx cache partial response when upstream prematutely close  
connection?

In our production environment, we found the following scenario requires  
one  
to manually clear proxy cache:

1. nginx asks upstrean for some large file, e.g., 5000KB

2. upstream send response, it flushes response header which (at least)  
contains content-length

3. Network is completely broken when 200KB was received by nginx. In  
about  
the same time, upstream closed connection by sending a FIN

4. nginx cache the partial response and use it to serve subsequent  
requests  
until expiration.

5. Browser request this large file then indefinitely hangs because  
content-length indicates there were more to come but actually nginx has  
nothing to send.

lei yang

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [June 8, 2011, 10:32am UTC](https://www.ruby-forum.com/t/proxy-cache-partial-response/208004/2 "2011-06-08T10:32:18Z")

</div>

Hi,

> will nginx cache partial response when upstream prematutely close  
> connection?

Sadly, yes.

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/91b2a8/32.png) [@SSSSSSS\_SS\_SSS](https://www.ruby-forum.com/u/SSSSSSS_SS_SSS)\
**Post date:** [June 11, 2011, 3:32am UTC](https://www.ruby-forum.com/t/proxy-cache-partial-response/208004/3 "2011-06-11T03:32:49Z")

</div>

Hi, my colleague found this interesting comment in nginx’s source code:

```
        if (p->upstream_done) {
            ngx_http_file_cache_update(r, u->pipe->temp_file);

        } else if (p->upstream_eof) {

```

- 

```
          /* TODO: check length & update cache */*

         ngx_http_file_cache_update(r, u->pipe->temp_file);

     } else if (p->upstream_error) {
         ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
     }

```

next time shall I ask a question, I’d better to do this first: \*grep -ri  
'TODO: ’ \*\*
