title: First request doesnt terminate (no FIN) uWSGI + nginx
body: <p>I am using nginx as a reverse proxy in front of a uWSGI server (flask apps). </p>
  
  <p>Due to a memory leak, use <code>--max-requests</code> to reload workers after so many calls.</p>
  
  <p>The issue is the following : When a worker just restarted/started, the first request it receives stays hanging between uWSGI and NGINX, the process time inside of the flask app is usual and very quick but the client waits until <code>uwsgi_send_timeout</code> is triggered.</p>
  
  <p>Using tcpdump to see the request (nginx is XXX.14 and uWSGI is XXX.11) : <a href="https://i.stack.imgur.com/sMjum.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sMjum.png" alt="tcpdump communcation between nginx XXX.14 and uWSGI XXX.11"></a></p>
  
  <p>You can see in the time column that it hangs for 300 seconds (uwsgi_send_timeout) eventhough the HTTP request has been received by NGINX... uWSGI just doesn't send a [FIN] packet to signal that the connexion is closed. Then NGINX triggers the timeout and closes the session. </p>
  
  <p>The end client receives a truncated response.. With a 200 status code. which is very frustrating.</p>
  
  <p>This happens at every worker reload, only once, the first request no matter how big the request.</p>
  
  <p>Does anyone have a workaround this issue? have I misconfigured something? </p>
  
  <h2>uwsgi.ini</h2>
  
  <pre><code>[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
  </code></pre>
  
  <h2>nginx-server.conf</h2>
  
  <pre><code>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;
      }
  </code></pre>