# Nginx silently drops response body of POST depending on its length

**URL:** <https://www.ruby-forum.com/t/nginx-silently-drops-response-body-of-post-depending-on-its-length/206734>\
**Category:** NGINX\
**Created:** [May 8, 2011, 9:15pm UTC](https://www.ruby-forum.com/t/nginx-silently-drops-response-body-of-post-depending-on-its-length/206734 "2011-05-08T21:15:56Z")\
**Posts on this page:** 4\
**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:** [May 8, 2011, 9:15pm UTC](https://www.ruby-forum.com/t/nginx-silently-drops-response-body-of-post-depending-on-its-length/206734/1 "2011-05-08T21:15:56Z")

</div>

I’ve come across an incredibly weird problem with POST responses using  
nginx 1.0.1 and uWSGI 0.9.7.2 on CentOS 5.6.

uWSGI successfully sends the response body to nginx, but nginx seems to  
ignore it if both (1) the request method is POST, and (2) the response  
length is less than 4052 bytes. The issue doesn’t occur when serving  
directly using `uwsgi --http`, so I’m pretty sure the problem is  
something to do with nginx.

To explain things in code, this Python results in the desired response:

…def app\_uwsgi(environ, start\_response):  
…start\_response(‘200 OK’, [(‘Content-type’, ‘text/html’)])  
…return [b’x’ \* 4052]

while this results in zero bytes being sent to the client for POST  
requests:

…def app\_uwsgi(environ, start\_response):  
…start\_response(‘200 OK’, [(‘Content-type’, ‘text/html’)])  
…return [b’x’ \* 4051]

I stripped down to a minimal nginx.conf, and the issue still occurs:

…events {  
…worker\_connections 1024;  
…}

…http {  
…upstream uwsgi\_connect {  
…server 127.0.0.1:39275;  
…}

…server {  
…listen 20101;  
…server\_name [domain.net](http://domain.net);

…location / {  
…uwsgi\_pass uwsgi\_connect;  
…include uwsgi\_params;  
…}  
…}  
…}

Does anyone have any clue what could be causing this behavior?

Posted at Nginx Forum:

> **[nginx silently drops response body of POST depending on its length](https://forum.nginx.org/read.php?2,196581,196581#msg-196581)**
>
> I've come across an incredibly weird problem with POST responses using nginx 1.0.1 and uWSGI 0.9.7.2 on CentOS 5.6. uWSGI successfully sends the response body to nginx, but nginx seems to ignore it if both (1) the request method is POST, and (2) the...

---

<div class="post-metadata">

**Author:** ![zildjohn01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zildjohn01](https://www.ruby-forum.com/u/zildjohn01)\
**Post date:** [May 9, 2011, 12:53pm UTC](https://www.ruby-forum.com/t/nginx-silently-drops-response-body-of-post-depending-on-its-length/206734/2 "2011-05-09T12:53:31Z")

</div>

Hello!

On Sun, May 08, 2011 at 03:15:28PM -0400, zildjohn01 wrote:

> Does anyone have any clue what could be causing this behavior?

As it was already said - you have to read body of POST before  
sending reply. Else you’ll get something like

… readv() failed (54: Connection reset by peer) while reading  
upstream …

in nginx error log and possibly incorrect reply (depending on various  
factors, including sizes and event method used).

Maxim D.

---

<div class="post-metadata">

**Author:** ![zildjohn01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zildjohn01](https://www.ruby-forum.com/u/zildjohn01)\
**Post date:** [May 9, 2011, 6:20pm UTC](https://www.ruby-forum.com/t/nginx-silently-drops-response-body-of-post-depending-on-its-length/206734/3 "2011-05-09T18:20:10Z")

</div>

Thanks, that helped point me to the issue. It turns out the problem was  
that I didn’t pass --pep3333-input to uWSGI, so it was converting all  
CRLFs to LFs in the request body, so CONTENT\_LENGTH didn’t match the  
data length. Passing that flag to uWSGI made it pass the raw stream to  
my app and solved the problem.

Posted at Nginx Forum:

> **[Re: nginx silently drops response body of POST depending on its length](https://forum.nginx.org/read.php?2,196581,196761#msg-196761)**
>
> I've come across an incredibly weird problem with POST responses using nginx 1.0.1 and uWSGI 0.9.7.2 on CentOS 5.6. uWSGI successfully sends the response body to nginx, but nginx seems to ignore it if both (1) the request method is POST, and (2) the...

---

<div class="post-metadata">

**Author:** ![zildjohn01](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zildjohn01](https://www.ruby-forum.com/u/zildjohn01)\
**Post date:** [May 10, 2011, 12:45am UTC](https://www.ruby-forum.com/t/nginx-silently-drops-response-body-of-post-depending-on-its-length/206734/4 "2011-05-10T00:45:12Z")

</div>

> 

Be sure to read POST body in your WSGI app if Content-Length \> 0,  
otherwise your socket queue will get clobbered (nginx will receive a  
close  
when there is still data available in the queue)

–  
Roberto De Ioris

> **[unbit - Overview](https://github.com/unbit)**
>
> makers of uWSGI and many more open source projects - unbit
