Nginx/uWSGI bug – empty post response

It turns out that in certain situations (which I haven’t investigated thoroughly enough, sorry), nginx/uWSGI drop the post response body! The fix appears to be to read the content of the post request (I came across this solution on StackOverflow). Something like this (using flask):

@app.route("/", methods=["POST"])
def my_postable():
    not_used = request.data # Very strange bug with uWSGI/nginx - unless you read the
                            # post data, the server returns a blank response!
    return render_template('my_postable_template.html')
About these ads

2 comments

  1. unbit (@unbit)

    That, from a general point of view, is the right behaviour (for nginx), as closing a socket without reading available data from it, is wrong. Throwing away what is already read (by nginx) could be avoided, but for technical reasons they prefer to throw away invalid sessions (that is why you will not find such behaviour on other proxy/webserver). By the way, uWSGI has an option for avoiding you to have to install a (slow) middleware. Check –post-buffering, and more generally check http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html that is a collection of “unexpected” behaviours.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s