Error: readv() failed (104: Connection reset by peer) while reading upstream
Asked Answered
S

2

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?

Stjohn answered 1/5, 2012 at 3:29 Comment(2)
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..Stjohn
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: flask.pocoo.org/snippets/47 uWSGI can help you with the --post-buffering option, but it is only a shortcut, nothing magic in it.Pretext
H
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.

Harneen answered 20/6, 2012 at 7:52 Comment(2)
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.Pretext
@Pretext 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.Harneen
E
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.

Emblazonment answered 10/7, 2017 at 15:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.