56

Trying to set the timeout for requests in uWSGI, I'm not sure of the correct setting. There seem to be multiple timeout options (socket, interface, etc.) and it's not readily evident which setting to configure or where to set it.

The behavior I'm looking for is to extend the time a request to the resource layer of a REST application can take.

Derrick
  • 2,502
  • 2
  • 24
  • 34
Juan Carlos Coto
  • 11,900
  • 22
  • 62
  • 102

3 Answers3

90

You're propably looking for the harakiri parameter - if request takes longer than specified harakiri time (in seconds), the request will be dropped and the corresponding worker recycled.

For standalone uwsgi (ini config):

[uwsgi]
http = 0.0.0.0:80
harakiri = 30
...

If you have nginx proxy before uwsgi you have to increase timeout as well:

  location / {
    proxy_pass http://my_uwsgi_upstream;
    proxy_read_timeout 30s;
    proxy_send_timeout 30s;
  }

If you want (for some strange reason) higher timeout than 60s, you might consider communication over uwsgi protocol. Configuration is quite similar nginx site:

location / {
    uwsgi_read_timeout 120s;
    uwsgi_send_timeout 120s;
    uwsgi_pass  my_upstream;
    include     uwsgi_params;
}

uwsgi:

[uwsgi]
socket = 0.0.0.0:80
protocol = uwsgi
harakiri = 120
...
Tombart
  • 30,520
  • 16
  • 123
  • 136
24

Setting http-timeout worked for me. I have http = :8080, so I assume if you use file system socket, you have to use socket-timeout.

iurii
  • 2,597
  • 22
  • 25
  • 1
    I was able to extend the timeout by only using the `http-timeout` parameter in the uwsgi config. I didn't need `--harakiri`. (and I also needed to set `proxy_read_timeout` and `proxy_send_timeout` in the nginx config as @Tombart said above) – nttaylor Aug 10 '17 at 17:09
  • will there be any issues if I used both ? I'm running into https://stackoverflow.com/questions/67407446/oserror-write-error-python-flask-sigpipe-writing-to-a-closed-pipe-socket-fd – DJ_Stuffy_K May 05 '21 at 20:08
  • In my case running `uwsgi` directly it was also the `--http-timeout` parameter. – white_gecko May 07 '21 at 18:04
-2

it worked for me by comment #master = true and put this, lazy-apps = true

in uwsgi.ini file

Muhammmed Nihad
  • 161
  • 1
  • 1
  • 12
Shahram
  • 27
  • 4