title: uWSGI raises OSError: write error during large request
body: <p>My application uses nginx, with uWSGI on the server side. When I do a large request (with a response time > 4s), the following appears:</p>
  
  <pre><code>SIGPIPE: writing to a closed pipe/socket/fd (probably the client
      disconnected) on request _URL_ (ip XX.XX.XX.XX) !!!
  
  uwsgi_response_writev_headers_and_body_do(): Broken pipe
      [core/writer.c line 287] during GET _URL_ (XX.XX.XX.XX)
  
  OSError: write error
  </code></pre>
  
  <p>It seems that uWSGI tries to write in a stream but this stream has already been closed.
  When I check nginx log (error.log):</p>
  
  <pre><code>upstream prematurely closed connection while reading response
      header from upstream ...
  </code></pre>
  
  <p>Of course, my client (REST client or browser) receives a 502 error.</p>
  
  <p>I always get this error after ~4s.</p>
  
  <p>However, I don't know how to prevent this issue.
  I tried to set some parameters in my nginx config file:</p>
  
  <pre><code>location my_api_url {
      [...]
      uwsgi_buffer_size 32k;
      uwsgi_buffers 8 32k;
      uwsgi_busy_buffers_size 32k;
  
      uwsgi_read_timeout 300;
      uwsgi_send_timeout 300;
  
      uwsgi_connect_timeout 60;
  }
  </code></pre>
  
  <p>But the issue is still here.
  I also tried to set these parameters in the uWSGI configuration file (wsgi.ini):</p>
  
  <pre><code>buffer-size=8192
  ignore-sigpipe=true
  ignore-write-errors=true
  </code></pre>
  
  <p>Before to try to optimize the response time, I hope this issue has a solution. I don't find one that's working in another post. I work with a large amount of data, so my response time, for some case, will be between 4-10s.</p>
  
  <p>Hope you can help me :)</p>
  
  <p>Thanks a lot in advance.</p>