第一个请求不会终止(没有FIN)uWSGI + nginx

问题描述 投票:1回答:1

我在uWSGI服务器(烧瓶应用程序)前面使用nginx作为反向代理。

由于内存泄漏,使用--max-requests在这么多电话后重新加载工作人员。

问题如下:当一个工作人员刚刚重新启动/启动时,它收到的第一个请求在uWSGI和NGINX之间保持挂起,烧瓶应用程序内部的处理时间通常非常快,但客户端等到uwsgi_send_timeout被触发。

使用tcpdump查看请求(nginx是XXX.14,uWSGI是XXX.11):tcpdump communcation between nginx XXX.14 and uWSGI XXX.11

您可以在时间列中看到它挂起300秒(uwsgi_send_timeout)尽管NGINX已收到HTTP请求... uWSGI只是不发送[FIN]数据包来发出连接已关闭的信号。然后NGINX触发超时并关闭会话。

最终客户端收到截断的响应..具有200状态代码。这非常令人沮丧。

这种情况发生在每个工作人员重新加载时,只有一次,第一个请求,无论请求有多大。

有没有人有解决这个问题的方法?我错误配置了什么?

uwsgi.ini

[uwsgi]
# Get the location of the app
module = api:app

plugin = python3
socket = :8000
manage-script-name = true
mount = /=api:app
cache2 = name=xxx,items=1024

# Had to increase buffer-size because of big authentication requests.
buffer-size = 8192

## Workers management
# Number of workers
processes = $(UWSGI_PROCESSES)
master = true
# Number of requests managed by 1 worker before reloading (reload is time expensive)
max-requests = $(UWSGI_MAX_REQUESTS)

lazy-apps = true

single-interpreter = true

nginx的-server.conf中

server {
    listen 443 ssl http2;
    client_max_body_size 50M;

    location @api {
        include uwsgi_params;
        uwsgi_pass api:8000;
        uwsgi_read_timeout 300;
        uwsgi_send_timeout 300;
    }
python nginx flask uwsgi
1个回答
0
投票

出于某种奇怪的原因,在nginx配置中添加参数uwsgi_buffering off;解决了这个问题。

我仍然不明白为什么,但现在这解决了我的问题。如果有人有有效的解释,请不要犹豫。

server {
    listen 443 ssl http2;
    client_max_body_size 50M;

    location @api {
        include uwsgi_params;
        uwsgi_pass api:8000;
        uwsgi_buffering off;
        uwsgi_read_timeout 300;
        uwsgi_send_timeout 300;
    }
© www.soinside.com 2019 - 2024. All rights reserved.