uwsgi IOError: write error

uwsgi IOError: write error

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

Wed Jan 13 15:26:04 2016 - uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.c line 296] during POST /company/get_unpaid_invoices_chart/ (86.34.48.7) IOError: write error

Wed Jan 13 15:26:20 2016 - uwsgi_response_write_headers_do(): Broken pipe [core/writer.c line 238] during GET /gestiune/print_pdf/nir/136194/ (89.122.255.186) IOError: write error

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

include uwsgi_params;

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

uwsgi_read_timeout 600;

uwsgi_send_timeout 600;

uwsgi_connect_timeout 60;

我确定出现错误的请求中 none 已超过 600 秒超时。 知道为什么会这样吗?

谢谢

问题是客户端中止连接,然后 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 连接。还有另一个关于这个问题的问题:()

另一种解决方案是将以下设置放入 uWSGI 配置中:

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

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