uWSGI 引发 OSError:在大请求期间写入错误 [英] uWSGI raises OSError: write error during large request
问题描述
我的应用程序使用 nginx,在服务器端使用 uWSGI.当我做一个大请求(响应时间> 4s)时,会出现以下内容:
My application uses nginx, with uWSGI on the server side. When I do a large request (with a response time > 4s), the following appears:
SIGPIPE: writing to a closed pipe/socket/fd (probably the client
disconnected) on request _URL_ (ip XX.XX.XX.XX) !!!
uwsgi_response_writev_headers_and_body_do(): Broken pipe
[core/writer.c line 287] during GET _URL_ (XX.XX.XX.XX)
OSError: write error
似乎 uWSGI 试图在一个流中写入,但这个流已经被关闭了.当我查看 nginx 日志(error.log)时:
It seems that uWSGI tries to write in a stream but this stream has already been closed. When I check nginx log (error.log):
upstream prematurely closed connection while reading response
header from upstream ...
当然,我的客户端(REST 客户端或浏览器)收到 502 错误.
Of course, my client (REST client or browser) receives a 502 error.
我总是在大约 4 秒后收到此错误.
I always get this error after ~4s.
但是,我不知道如何防止这个问题.我试图在我的 nginx 配置文件中设置一些参数:
However, I don't know how to prevent this issue. I tried to set some parameters in my nginx config file:
location my_api_url {
[...]
uwsgi_buffer_size 32k;
uwsgi_buffers 8 32k;
uwsgi_busy_buffers_size 32k;
uwsgi_read_timeout 300;
uwsgi_send_timeout 300;
uwsgi_connect_timeout 60;
}
但问题仍然存在.我也尝试在uWSGI配置文件(wsgi.ini)中设置这些参数:
But the issue is still here. I also tried to set these parameters in the uWSGI configuration file (wsgi.ini):
buffer-size=8192
ignore-sigpipe=true
ignore-write-errors=true
在尝试优化响应时间之前,希望这个问题有解决方案.我没有找到在另一篇文章中工作的人.我处理大量数据,因此在某些情况下,我的响应时间会在 4-10 秒之间.
Before to try to optimize the response time, I hope this issue has a solution. I don't find one that's working in another post. I work with a large amount of data, so my response time, for some case, will be between 4-10s.
希望你能帮助我:)
非常感谢.
推荐答案
当你上传东西时,你可能会使用分块编码.有 uWSGI 选项--chunked-input-timeout
,默认情况下是 4 秒(它 defaults--socket-timeout
的值,即 4 秒).
It may be the case that when you upload things, you use chunked encoding.
There is uWSGI option
--chunked-input-timeout
,
that by default is 4 seconds (it defaults
to value of --socket-timeout
, which is 4 seconds).
虽然理论上问题可能出在其他地方,但我建议您尝试上述选项.另外,烦人的异常是我有
Though problem theoretically may lie somewhere else, I suggest you to try aforementioned options. Plus, annoying exceptions are the reason why I have
ignore-sigpipe=true
ignore-write-errors=true
disable-write-exception=true
在我的 uWSGI 配置中(注意我提供了 3 个选项,而不是 2 个):
in my uWSGI config (note that I provide 3 options, not 2):
ignore-sigpipe
使 uWSGI 不显示 SIGPIPE 错误;ignore-write-errors
使它不显示错误例如uwsgi_response_writev_headers_and_body_do
;disable-write-exception
防止OSError
写入时生成.
ignore-sigpipe
makes uWSGI not show SIGPIPE errors;ignore-write-errors
makes it not show errors with e.g.uwsgi_response_writev_headers_and_body_do
;disable-write-exception
preventsOSError
generation on writes.
这篇关于uWSGI 引发 OSError:在大请求期间写入错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!