问题 uwsgi IOError:写入错误


我的django应用程序的nginx + uwsgi配置有问题,我在uwsgi错误日志中不断收到此错误:

1月13日星期三15:26:04 - uwsgi_response_writev_headers_and_body_do():在POST / company / get_unpaid_invoices_chart /(86.34.48.7)期间断管[core / writer.c第296行]   IOError:写入错误

2016年1月13日星期三15:26:20 - uwsgi_response_write_headers_do():破碎   在GET期间管道[core / writer.c第238行]   / gestiune / print_pdf / nir / 136194 /(89.122.255.186)IOError:写入错误

我没有收到他们的所有要求,但我每分钟都得到几个。 我搜索了它,我明白这是因为在uwsgi想要编写响应时nginx关闭了与uwsgi的连接。 这看起来很奇怪,因为在我的nginx配置中我有这个:

包括uwsgi_params;

uwsgi_pass unix:/home/project/django/sbo_cloud/site.sock;

uwsgi_read_timeout 600;

uwsgi_send_timeout 600;

uwsgi_connect_timeout 60;

我确信没有出现错误的请求超过600秒超时。 知道为什么会这样吗?

谢谢


4107
2018-01-13 13:54


起源



答案:


问题是客户端中止连接,然后Nginx关闭连接而不告诉uwsgi中止。然后当uwsgi返回结果时,套接字已经关闭。 Nginx在日志中写入499错误,uwsgi抛出IOError。

非最佳解决方案是告诉Nginx不要关闭套接字并等待uwsgi返回响应。

将uwsgi_ignore_client_abort放在你的nginx.config中。

location @app {
    include uwsgi_params;
    uwsgi_pass unix:///tmp/uwsgi.sock;

    # when a client closes the connection then keep the channel to uwsgi open. Otherwise uwsgi throws and IOError
    uwsgi_ignore_client_abort on;
}

目前尚不清楚是否有可能告诉Nginx关闭uwsgi连接。关于这个问题还有另一个问题:(将http中止/关闭从nginx传播到uwsgi / Django


10
2017-11-02 08:36





替代解决方案是在uWSGI配置中放置以下设置:

ignore-sigpipe = true
ignore-write-errors = true
disable-write-exception = true

看到 https://github.com/getsentry/raven-python/issues/732


1
2018-06-08 09:54