Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx connection reset, response from uWsgi lost

Tags:

I have a django app hosted via Nginx and uWsgi. In a certain very simple request, I get different behaviour for GET and POST, which should not be the case.

The uWsgi daemon log:

[pid: 32454|app: 0|req: 5/17] 127.0.0.1 () {36 vars in 636 bytes} [Tue Oct 19 11:18:36 2010] POST /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ => generated 80 bytes in 3 msecs (HTTP/1.0 440) 1 headers in 76 bytes (0 async switches on async core 0) [pid: 32455|app: 0|req: 5/18] 127.0.0.1 () {32 vars in 521 bytes} [Tue Oct 19 11:18:50 2010] GET /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ => generated 80 bytes in 3 msecs (HTTP/1.0 440) 1 headers in 76 bytes (0 async switches on async core 0) 

The Nginx accesslog:

127.0.0.1 - - [19/Oct/2010:18:18:36 +0200] "POST /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ HTTP/1.0" 440 0 "-" "curl/7.19.5 (i486-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15" 127.0.0.1 - - [19/Oct/2010:18:18:50 +0200] "GET /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ HTTP/1.0" 440 80 "-" "curl/7.19.5 (i486-pc-linux-gnu) libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15" 

The Nginx errorlog:

2010/10/19 18:18:36 [error] 4615#0: *5 readv() failed (104: Connection reset by peer) while reading upstream, client: 127.0.0.1, server: localhost, request: "POST /buy/76d4f520ae82e1dfd35564aed64a885b/a_2/10/ HTTP/1.0", upstream: "uwsgi://unix:sock/uwsgi.sock:", host: "localhost:9201" 

In essence, Nginx somewhere loses the response if I use POST, not so if I use GET.

Anybody knows something about that?

like image 835
Ulf Avatar asked Oct 19 '10 16:10

Ulf


People also ask

Can I use uWSGI without nginx?

Can I then ditch NGINX? uWSGI could be used as a standalone web server in production, but that is not it's intentional use. It may sound odd, but uWSGI was always supposed to be a go-between a full-featured web server like NGINX and your Python files.

What is uWSGI in nginx?

uwsgi: A fast, binary protocol implemented by the uWSGI server to communicate with a more full-featured web server. This is a wire protocol, not a transport protocol. It is the preferred way to speak to web servers that are proxying requests to uWSGI.

What is the use of uWSGI?

uwsgi (all lowercase) is the native binary protocol that uWSGI uses to communicate with other servers. uWSGI is often used in conjunction with web servers such as Cherokee and Nginx, which offer direct support for uWSGI's native uwsgi protocol, to serve Python web applications such as Django.


2 Answers

Pass --post-buffering 1 to uwsgi

This will automatically buffer all the http body > 1 byte

The problem is raised by the way nginx manages upstream disconnections

like image 118
roberto Avatar answered Oct 02 '22 22:10

roberto


I hit the same issue, but on my case I can't disable "uwsgi_pass_request_body" as most times (but not always) my app do need the POST data.

This is the workaround I found, while this issue is not fixed in uwsgi: http://permalink.gmane.org/gmane.comp.python.wsgi.uwsgi.general/813

import django.core.handlers.wsgi class ForcePostHandler(django.core.handlers.wsgi.WSGIHandler):     """Workaround for: http://lists.unbit.it/pipermail/uwsgi/2011-February/001395.html     """     def get_response(self, request):         request.POST # force reading of POST data         return super(ForcePostHandler, self).get_response(request)  application = ForcePostHandler() 
like image 21
ehabkost Avatar answered Oct 03 '22 00:10

ehabkost