UWSGI 在作为服务和 POST 大文件启动时崩溃:ConnectionError
UWSGI crash when started as service and POST big file: ConnectionError
我在使用 uwsgi 时遇到了一个莫名其妙的问题:上传大文件时会发生不规则的崩溃。场景:
上下文
对于简单的wsgi应用,这里是python Flask应用在/home/bastien/Projects/test_upload/wsgi.py:
# -*- coding: utf-8 -*-
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
def hello_world():
f = request.files['file'].read()
return 'Hello, World! {}'.format(len(f))
application = app
当:
时没有崩溃
使用这个配置uwsgi文件,/etc/uwsgi/apps-available/test_upload.ini:
[uwsgi]
plugins = python3
chdir = /home/bastien/Projects/test_upload/tracim
home = /home/bastien/Projects/test_upload/venv3.4
module = wsgi
callable = application
enable-threads = true
env = PYTHON_EGG_CACHE=/tmp
limit-post = 0
chmod-socket = 660
vacuum = true
运行 uwsgi 与:
uwsgi -i /etc/uwsgi/apps-available/test_upload.ini --http-socket :6543
并发送文件 (~262Mo) /httpie
:
http -h -f POST :6543 'file@/home/bastien/Téléchargements/pycharm-professional-2017.2.3.tar.gz'
HTTP请求可以重复,不会崩溃。
崩溃时:
使用这个配置uwsgi文件,/etc/uwsgi/apps-available/test_upload.ini with symbolic link into /etc/uwsgi/apps-enabled:
[uwsgi]
plugins = python3
chdir = /home/bastien/Projects/test_upload/tracim
home = /home/bastien/Projects/test_upload/venv3.4
module = wsgi
callable = application
http-socket = :4321
enable-threads = true
env = PYTHON_EGG_CACHE=/tmp
limit-post = 0
chmod-socket = 660
vacuum = true
注意:唯一的区别是http-socket = :4321
运行 uwsgi 与 service uwsgi start
(在 debian 8.9 上)并发送文件:
http -h -f POST :4321 'file@/home/bastien/Téléchargements/pycharm-professional-2017.2.3.tar.gz'
这个请求会工作一次,有时会工作两次:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 5188
Content-Type: text/html; charset=utf-8
Pragma: no-cache
但最终崩溃:
http: error: ConnectionError: ('Connection aborted.', BadStatusLine("''",)) while doing POST request to URL: http://localhost:4321/
注意:任何wsgi应用都可以用于reproduce
注意: uwsgi 或应用程序没有生成关于此的日志"error"
总结:
错误不一致,唯一不同的是 uwsgi 作为服务使用:
- Debian 8.9
- uwsgi
2.0.7-1+deb8u1
安装了 apt
问题
如何产生这种差异?我在哪里可以搜索到 如何通过 service
命令启动 uwsgi ?
Debian 9 与 apt 版本的 uwsgi 一起使用时问题已解决 2.0.14+20161117-3
。
我在使用 uwsgi 时遇到了一个莫名其妙的问题:上传大文件时会发生不规则的崩溃。场景:
上下文
对于简单的wsgi应用,这里是python Flask应用在/home/bastien/Projects/test_upload/wsgi.py:
# -*- coding: utf-8 -*-
from flask import Flask, request
app = Flask(__name__)
@app.route('/', methods=['POST'])
def hello_world():
f = request.files['file'].read()
return 'Hello, World! {}'.format(len(f))
application = app
当:
时没有崩溃使用这个配置uwsgi文件,/etc/uwsgi/apps-available/test_upload.ini:
[uwsgi]
plugins = python3
chdir = /home/bastien/Projects/test_upload/tracim
home = /home/bastien/Projects/test_upload/venv3.4
module = wsgi
callable = application
enable-threads = true
env = PYTHON_EGG_CACHE=/tmp
limit-post = 0
chmod-socket = 660
vacuum = true
运行 uwsgi 与:
uwsgi -i /etc/uwsgi/apps-available/test_upload.ini --http-socket :6543
并发送文件 (~262Mo) /httpie
:
http -h -f POST :6543 'file@/home/bastien/Téléchargements/pycharm-professional-2017.2.3.tar.gz'
HTTP请求可以重复,不会崩溃。
崩溃时:
使用这个配置uwsgi文件,/etc/uwsgi/apps-available/test_upload.ini with symbolic link into /etc/uwsgi/apps-enabled:
[uwsgi]
plugins = python3
chdir = /home/bastien/Projects/test_upload/tracim
home = /home/bastien/Projects/test_upload/venv3.4
module = wsgi
callable = application
http-socket = :4321
enable-threads = true
env = PYTHON_EGG_CACHE=/tmp
limit-post = 0
chmod-socket = 660
vacuum = true
注意:唯一的区别是http-socket = :4321
运行 uwsgi 与 service uwsgi start
(在 debian 8.9 上)并发送文件:
http -h -f POST :4321 'file@/home/bastien/Téléchargements/pycharm-professional-2017.2.3.tar.gz'
这个请求会工作一次,有时会工作两次:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Length: 5188
Content-Type: text/html; charset=utf-8
Pragma: no-cache
但最终崩溃:
http: error: ConnectionError: ('Connection aborted.', BadStatusLine("''",)) while doing POST request to URL: http://localhost:4321/
注意:任何wsgi应用都可以用于reproduce
注意: uwsgi 或应用程序没有生成关于此的日志"error"
总结:
错误不一致,唯一不同的是 uwsgi 作为服务使用:
- Debian 8.9
- uwsgi
2.0.7-1+deb8u1
安装了 apt
问题
如何产生这种差异?我在哪里可以搜索到 如何通过 service
命令启动 uwsgi ?
Debian 9 与 apt 版本的 uwsgi 一起使用时问题已解决 2.0.14+20161117-3
。