uWSGI错误hr_instance_read():由对等方重置连接

时间:2018-05-05 12:19:17

标签: python nginx uwsgi

我使用uWSGI和NGINX作为反向代理部署了一个烧瓶Web应用程序。应用程序响应时间平均约为9毫秒,但在一批请求后,我的工作程序崩溃,并且我在uWSGI日志中记录了该日志:

type Mutation {
  post(url: String!, description: String!): Link!
  signup(email: String!, password: String!, name: String!): AuthPayload
  login(email: String!, password: String!): AuthPayload
}

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]

ENV:

[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

1 个答案:

答案 0 :(得分:0)

我在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请求具有主体(例如,   表单),则必须在应用程序中阅读(使用)它。如果你这样做   不这样做,与您的网络服务器的通讯套接字可能是   破烂不堪。如果您很懒,可以使用后缓冲选项   会自动为您读取数据。对于机架应用,这是   自动启用。