python - 作为服务启动并 POST 大文件时 UWSGI 崩溃 : ConnectionError

标签 python debian uwsgi

我在使用 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

并使用 /httpie 发送文件 (~262Mo):

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,并带有符号链接(symbolic link)到/etc/uwsgi/apps-enabled: p>

[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

使用 service uwsgi start 运行 uwsgi(在 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 应用程序都可用于重现

注意:uwsgi 或应用程序不会生成有关此“错误”的日志

摘要:

错误不一致,唯一的区别是 uwsgi 用作​​服务:

  • Debian 8.9
  • uwsgi 2.0.7-1+deb8u1 apt 已安装

问题

如何产生这种差异?我在哪里可以搜索以了解如何通过service命令启动uwsgi?

最佳答案

在 apt 版本 2.0.14+20161117-3 中使用 Debian 9 和 uwsgi 时出现的问题已解决。

关于python - 作为服务启动并 POST 大文件时 UWSGI 崩溃 : ConnectionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47032355/

相关文章:

python - 在 Django 中只允许模型的一个实例

python - 按字典中键的值合并两个字典列表

python - 使用 Python 描述符触发类成员的内容

php - 当 where 子句中的日期时间介于之间时 MySQL 查询速度慢

linux - 我如何将 postinst 脚本与 fakeroot deb 包生成器一起使用

django - 重新启动以查看更改?切诺基 + uWSGI + Django/Pinax + Virtualenv

python - 如何在 Python 中计算 Jaccard 指数?

linux - 使用 Linux 计算机作为 USB 耦合器

python - Flask/uWSGI 抛出错误无法加载 app 0 (mountpoint ='')

django - uwsgi 服务的静态文件的 Nginx 缓存