# uWSGI - upstream prematurely closed connection while reading response header from upstream

**URL:** <https://www.ruby-forum.com/t/uwsgi-upstream-prematurely-closed-connection-while-reading-response-header-from-upstream/242459>\
**Category:** NGINX\
**Created:** [June 25, 2015, 3:05am UTC](https://www.ruby-forum.com/t/uwsgi-upstream-prematurely-closed-connection-while-reading-response-header-from-upstream/242459 "2015-06-25T03:05:41Z")\
**Posts on this page:** 4\
**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:** [June 25, 2015, 3:05am UTC](https://www.ruby-forum.com/t/uwsgi-upstream-prematurely-closed-connection-while-reading-response-header-from-upstream/242459/1 "2015-06-25T03:05:41Z")

</div>

Hi,

I have a script which runs for 70 seconds. I have NGINX connecting to it  
via  
uWSGI.

I have set “uwsgi\_read\_timeout 90;”. However, NGINX drops the connection  
exactly at 60 seconds -

“upstream prematurely closed connection while reading response header  
from  
upstream”

My script continues to run and completes after 70 seconds, however my  
browser connection has died before then (502 error).

The option “uwsgi\_read\_timeout” does its job for anything less than 60  
seconds (ie uwsgi\_read\_timeout 30;) and terminates with a 504 error as  
expected.

I don’t quite understand what is catching the 502 bad gateway error even  
though I have instructed nginx to permit a uwsgi read timeout of 90

Other -

I also have set “keepalive\_timeout 300 300;”

Any ideas as to the cause? I see numerous posts on the internet advising  
to  
use “uwsgi\_read\_timeout”

Thanks

Posted at Nginx Forum:

> **[uWSGI - upstream prematurely closed connection while reading response header...](https://forum.nginx.org/read.php?2,259882,259882#msg-259882)**
>
> Hi, I have a script which runs for 70 seconds. I have NGINX connecting to it via uWSGI. I have set "uwsgi\_read\_timeout 90;". However, NGINX drops the connection exactly at 60 seconds - "upstream prematurely closed connection while...

---

<div class="post-metadata">

**Author:** ![ajjH6](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@ajjH6](https://www.ruby-forum.com/u/ajjH6)\
**Post date:** [June 25, 2015, 3:07am UTC](https://www.ruby-forum.com/t/uwsgi-upstream-prematurely-closed-connection-while-reading-response-header-from-upstream/242459/2 "2015-06-25T03:07:27Z")

</div>

BTW - this is uWSGI HTTP

Posted at Nginx Forum:

> **[Re: uWSGI - upstream prematurely closed connection while reading response...](https://forum.nginx.org/read.php?2,259882,259883#msg-259883)**
>
> Hi, I have a script which runs for 70 seconds. I have NGINX connecting to it via uWSGI. I have set "uwsgi\_read\_timeout 90;". However, NGINX drops the connection exactly at 60 seconds - "upstream prematurely closed connection while...

---

<div class="post-metadata">

**Author:** ![ajjH6](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@ajjH6](https://www.ruby-forum.com/u/ajjH6)\
**Post date:** [July 3, 2015, 6:45am UTC](https://www.ruby-forum.com/t/uwsgi-upstream-prematurely-closed-connection-while-reading-response-header-from-upstream/242459/3 "2015-07-03T06:45:50Z")

</div>

Any ideas? I just want to run a uWSGI app for more than 60 seconds?

Posted at Nginx Forum:

> **[Re: uWSGI - upstream prematurely closed connection while reading response...](https://forum.nginx.org/read.php?2,259882,260022#msg-260022)**
>
> Hi, I have a script which runs for 70 seconds. I have NGINX connecting to it via uWSGI. I have set "uwsgi\_read\_timeout 90;". However, NGINX drops the connection exactly at 60 seconds - "upstream prematurely closed connection while...

---

<div class="post-metadata">

**Author:** ![ajjH6](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ad7895/32.png) [@ajjH6](https://www.ruby-forum.com/u/ajjH6)\
**Post date:** [July 3, 2015, 7:07pm UTC](https://www.ruby-forum.com/t/uwsgi-upstream-prematurely-closed-connection-while-reading-response-header-from-upstream/242459/4 "2015-07-03T19:07:44Z")

</div>

It sounds like uwsgi setting problem. Prematurely closed connection  
means  
Nginx is not expecting that.
