uwsgi + nginx + flask: upstream prematurely closed

后端 未结 8 1948
暗喜
暗喜 2020-12-16 13:28

I created an endpoint on my flask which generates a spreadsheet from a database query (remote db) and then sends it as a download in the browser. Flask doesn\'t throw any er

8条回答
  •  伪装坚强ぢ
    2020-12-16 14:08

    I had the same sporadic errors in Elastic Beanstalk single-container Docker WSGI app deployment. On EC2 instance of the environment upstream configuration looks like:

    upstream docker {
        server 172.17.0.3:8080;
        keepalive 256;
    }
    

    With this default upstream simple load test like:

    siege -b -c 16 -t 60S -T 'application/json' 'http://host/foo POST {"foo": "bar"}'
    

    ...on the EC2 led to availability of ~70%. The rest were 502 errors caused by upstream prematurely closed connection while reading response header from upstream.

    The solution was to either remove keepalive setting from the upstream configuration, or which is easier and more reasonable, is to enable HTTP keep-alive at uWSGI's side as well, with --http-keepalive (available since 1.9).

提交回复
热议问题