【问题标题】:First request doesnt terminate (no FIN) uWSGI + nginx第一个请求没有终止(没有 FIN)uWSGI + nginx
【发布时间】:2019-08-01 00:24:43
【问题描述】:

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

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

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

使用tcpdump查看请求(nginx是XXX.14,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】:

    由于一些奇怪的原因,在 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;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 1970-01-01
      • 2017-10-02
      • 1970-01-01
      • 2015-12-29
      • 1970-01-01
      相关资源
      最近更新 更多