nginx uWSGI错误hr_instance_read():对等设备重置连接

gr8qqesn  于 2023-10-17  发布在  Nginx
关注(0)|答案(1)|浏览(166)

我已经部署了一个使用uWSGI和NGINX作为反向代理的flask web应用程序。应用程序的响应时间平均约为9ms,但在一批请求之后,我的工作人员崩溃了,我在uWSGI日志上得到了以下日志:

[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 24488] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 4059] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 46764] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 9951] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 9449] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 51355] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 39565] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 63142] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 7861] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 10165] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 10917] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]
[uwsgi-http key: backend client_addr: 172.17.0.1 client_port: 20392] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]

uWSGI配置:

[uwsgi]
http = 0.0.0.0:7000
wsgi-file = app.py
callable = app
processes = 5
lazy = true
lazy-apps = true
buffer-size = 16384
logto = /root/logs/data-gathering.log

环境:

uWSGI==2.0.17
Flask==0.12.2
ha5z0ras

ha5z0ras1#

我在uWSGI本地HTTP服务器上遇到了同样的问题。具有以下配置:

https = :8443,app.crt,app.key,HIGH,!ca.crt
http-workers = 2
http-buffer-size = 32768

; applications
mount = /=/app.py
mount = /asq=/asq.py

; process managment
master = true
vacuum = true
single-interpreter = true
pidfile = /tmp/uwsgi.pid
enable-threads = true
cpu-affinity = 1
processes = 4
threads = 2
offload-threads = 1

close-on-exec = true
buffer-size = 32768

我总是得到:

[uwsgi-http key: 192.168.1.200:8443 client_addr: 192.168.1.200 client_port: 20179] hr_instance_read(): Connection reset by peer [plugins/http/http.c line 647]

在我的例子中,我正在执行POST请求,而不是消耗身体。因此,在将post-buffering = 1添加到配置后,一切都开始正常工作。没有标志,仅阅读POST数据,结果相同。
从uWSGI的“要知道的事情”:
如果一个HTTP请求有一个主体(就像一个表单生成的POST请求),你必须在你的应用程序中读取(消费)它。如果你不这样做,与你的网络服务器的通信套接字可能会被破坏。如果你很懒,你可以使用后缓冲选项,它会自动为你读取数据。对于Rack应用程序,此选项自动启用。

相关问题