10

I have facebook apps with flask with nginx and uwsgi. When it receive POST from facebook, it always has error:

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

But when I access my apps directly (with GET method), it ran smoothly. What I've done:

  1. Limit @app.route with POST method only - doesn't work.
  2. Add limit in wsgi: uwsgi_buffer_size (in case request from facebook is big), and uwsgi_harakiri (in case uwsgi provide timeout before finish it request) - doesn't work.

I have workaround in django but can't figure out yet how to implement in flask. Could anyone help please?

Community
  • 1
  • 1
asofyan
  • 317
  • 2
  • 10
  • the answer is bit ridiculous for me. I have to process all post data, even if my process is doing nothing. if "nothing" not in request.form: pass. Its working.. Btw, facebook open the app with POST request, so I should add that for every route. There must be better way of doing it.. – asofyan May 01 '12 at 05:20
  • If there is datas on a socket you have to read them (no other choices). On the flask wiki you can find a middleware to bypass this common problem on proxied setup: http://flask.pocoo.org/snippets/47/ uWSGI can help you with the --post-buffering option, but it is only a shortcut, nothing magic in it. – roberto Jun 23 '12 at 14:33

2 Answers2

4

This is the bug of uwsgi. You can get more from [uWSGI] Several bugs .

The simple solution is that you must read the POST body by wsgi.input, even through POST body is null or you don't need POST params.

Yang Juven
  • 314
  • 1
  • 3
  • 8
  • this has nothing to do with uWSGI (and it is certainly not a bug). Closing a socket without reading datas in it, is a wrong programming behaviour. uWSGI can help you (if you do not want to change your code) buffering post datas automatically via the --post-buffering option. – roberto Jun 23 '12 at 14:28
  • @roberto Thank you. When add post-buffering option in uwsgi setting, it works. But in some cases, for example, post request has no params, it's not need to read post body from wsgi.input. So I don't think it's the programmers' mistake. – Yang Juven Jun 29 '12 at 06:14
2

The issue is that "upstream" (the actual process that nginx is proxing) is closing the connection.

In my case, Django is my web server and I needed to set DATA_UPLOAD_MAX_NUMBER_FIELDS to be larger because there were too many fields in the POST request.

Collin Anderson
  • 14,787
  • 6
  • 68
  • 57