uwsgi IOError:写入错误

问题描述 投票:15回答:2

我的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:写入错误

1月13日星期三15:26:20 - uwsgi_response_write_headers_do():在GET / gestiune / print_pdf / nir / 136194 /(89.122.255.186)期间断管[core / writer.c第238行] 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秒超时。知道为什么会这样吗?

谢谢

nginx uwsgi
2个回答
18
投票

问题是客户端中止连接,然后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 an IOError
    uwsgi_ignore_client_abort on;
}

目前尚不清楚是否有可能告诉Nginx关闭uwsgi连接。关于这个问题还有另一个问题:(Propagate http abort/close from nginx to uwsgi / Django


5
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.