# Upstrea/ Keepalive strange behaviour

**URL:** <https://www.ruby-forum.com/t/upstrea-keepalive-strange-behaviour/237975>\
**Category:** NGINX\
**Created:** [December 9, 2013, 5:52pm UTC](https://www.ruby-forum.com/t/upstrea-keepalive-strange-behaviour/237975 "2013-12-09T17:52:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [December 9, 2013, 5:52pm UTC](https://www.ruby-forum.com/t/upstrea-keepalive-strange-behaviour/237975/1 "2013-12-09T17:52:43Z")

</div>

Hello all,

I have a strange behavior when using upstream/keepalive and it could be  
fine if someone can give me some feedback regarding this setup.

I have multiple locations with proxy\_pass directive, i use  
proxy\_http\_version 1.1 and “Connection” header is cleared.  
In the upstream block, i have 2 or more upstream IP and i have add the  
directive keepalive.

Now, sometimes i see this error log : “upstream prematurely closed  
connection while reading response header from upstream”.

A tcpdump show that nginx send a GET to his upstream but the TCP  
connection is closed and nginx don’t receive the response from  
upstream. Most of the time, nginx uses another upstream server and the  
transaction is successfully completed.  
This behavior appears with different upstream server.

If someone has experiencing this kind of issue, feedback are welcome !

Thanks,  
BR.

–  
David Donchez - Lead Engineer, Research & Engineering  
SmartJog | T: +33 1 5868 6190  
27 Blvd Hippolyte Marquès, 94200 Ivry-sur-Seine, France  
[www.smartjog.com](http://www.smartjog.com) | a TDF Group company

---

<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:** [December 10, 2013, 6:38pm UTC](https://www.ruby-forum.com/t/upstrea-keepalive-strange-behaviour/237975/2 "2013-12-10T18:38:27Z")

</div>

Hello!

On Mon, Dec 09, 2013 at 04:52:11PM +0000, David DONCHEZ wrote:

> Now, sometimes i see this error log : “upstream prematurely closed  
> connection while reading response header from upstream”.
> 
> A tcpdump show that nginx send a GET to his upstream but the TCP  
> connection is closed and nginx don’t receive the response from  
> upstream. Most of the time, nginx uses another upstream server and the  
> transaction is successfully completed.  
> This behavior appears with different upstream server.

As per HTTP specification, persistent connection can be closed by  
the server at any time, and clients should handle this. That is,  
that’s more or less normal, and nginx is expected to handle this  
fine by using another upstream server if this happens.

–  
Maxim D.  
[http://nginx.org/](http://nginx.org/)

---

<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:** [December 11, 2013, 9:59am UTC](https://www.ruby-forum.com/t/upstrea-keepalive-strange-behaviour/237975/3 "2013-12-11T09:59:06Z")

</div>

Hello Maxim,

> As per HTTP specification, persistent connection can be closed by  
> the server at any time, and clients should handle this. That is,  
> that’s more or less normal, and nginx is expected to handle this  
> fine by using another upstream server if this happens.

Thanks for your reply. I suspected that this behavior was normal but  
it’s good to have a confirmation from your side.

–  
David Donchez - Lead Engineer, Research & Engineering  
SmartJog | T: +33 1 5868 6190  
27 Blvd Hippolyte Marquès, 94200 Ivry-sur-Seine, France  
[www.smartjog.com](http://www.smartjog.com) | a TDF Group company
