Python 如何调试';OSError:无法写入数据';在我的烧瓶服务器上?
我正在弹性Beanstalk(代码链接:)上运行一个Flask应用程序(带有一些Django ORM)。然而,我不断收到来自Elastic Beanstalk的关于5xx失败(约5-25%失败)的通知。查看日志(/var/logs/httpd/error\u log),我看到以下错误: 错误1:Python 如何调试';OSError:无法写入数据';在我的烧瓶服务器上?,python,flask,mod-wsgi,Python,Flask,Mod Wsgi,我正在弹性Beanstalk(代码链接:)上运行一个Flask应用程序(带有一些Django ORM)。然而,我不断收到来自Elastic Beanstalk的关于5xx失败(约5-25%失败)的通知。查看日志(/var/logs/httpd/error\u log),我看到以下错误: 错误1: [Fri Nov 13 13:58:55.487007 2020] [:error] [pid 14630] [remote {load_balancer_ip_address:port1}] mod_
[Fri Nov 13 13:58:55.487007 2020] [:error] [pid 14630] [remote {load_balancer_ip_address:port1}] mod_wsgi (pid=14630): Exception occurred processing WSGI script '/opt/python/current/app/wsgi.py'.
[Fri Nov 13 13:58:55.487070 2020] [:error] [pid 14630] [remote {load_balancer_ip_address:port1}] OSError: failed to write data
错误2:
[Fri Nov 13 13:59:55.486449 2020] [:error] [pid 17765] (70008)Partial results are valid but processing is incomplete: [client {load_balancer_ip_address:port2}] mod_wsgi (pid=17765): Unable to get bucket brigade for request
对每一个进行快速的grep-c(结果:5418)可以确认它们很可能是相关的问题,尽管在PID和不同的LB端口中没有相关性
我对堆栈溢出进行了一些研究,发现了以下相关问题:
小结:有可能是由于连接中断或Apache子工作进程被终止,导致连接不稳定的客户端导致了此问题
调用此API的大多数客户端都是Android和iOS客户端,它们正在上载物联网数据,因此我的一个假设是,客户端正在尝试上载大量数据,并且正在超时。然而,令人沮丧的是,除了“OSError:无法写入数据”之外,没有更具描述性的堆栈跟踪
我目前正在研究如何增加服务器上的超时时间(并放大以避免任何性能问题),看看这一假设是否成立
但是,有没有更好的策略来从根本上解决问题,而不是反复试验
具体而言:
WSGISocketPrefix run/wsgi
WSGIRestrictEmbedded On
<VirtualHost *:80>
Alias /static/ /opt/python/current/app/frontend/static/
<Directory /opt/python/current/app/frontend/static/>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /opt/python/current/app/wsgi.py
<Directory /opt/python/current/app/>
Require all granted
</Directory>
WSGIDaemonProcess wsgi processes=2 threads=20 display-name=%{GROUP} \
python-home=/opt/python/run/venv/ \
python-path=/opt/python/current/app user=wsgi group=wsgi \
home=/opt/python/current/app
WSGIProcessGroup wsgi
</VirtualHost>
LogFormat "%h (%{X-Forwarded-For}i) %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
WSGIApplicationGroup %{GLOBAL}
WSGISocketPrefix运行/wsgi
WSGirestricton嵌入式
别名/static//opt/python/current/app/frontend/static/
命令允许,拒绝
通融
WSGIScriptAlias//opt/python/current/app/wsgi.py
要求所有授权
WSGIDaemonProcess wsgi PROCESS=2线程=20显示名称=%{GROUP}\
python home=/opt/python/run/venv/\
python路径=/opt/python/current/app user=wsgi组=wsgi\
home=/opt/python/current/app
WSGIProcessGroup wsgi
日志格式“%h(%{X-Forwarded-For}i)%l%u%t\%r\“%>s%b\“%{Referer}i\”\“%{User-Agent}i\”组合
WSGIApplicationGroup%{GLOBAL}
根据WSGIDaemon文档,它看起来不存在默认的请求超时。我发现这篇文章与我的问题()非常接近,并将负载平衡器空闲超时时间从60秒更新到240秒,并扩大了实例数量。我只看到又发生了一个错误实例,但到目前为止还没有其他实例。