44

I have used nginx and gunicorn to host my website in two servers,

Both server have same versions of packages and website is successfully hosted,

But in one of my server gunicorn always gets timeout and I get error

[CRITICAL]Worker Timeout
Booting worker with pid
Worker cannot boot with pid

And after this I get 502 Badgateway error in webpage. I have to restart the gunicorn process to bring up website.

Following is the error log :

2014-02-16 14:29:53 [1267] [CRITICAL] WORKER TIMEOUT (pid:4994)
2014-02-16 14:29:53 [1267] [CRITICAL] WORKER TIMEOUT (pid:4994)   
2014-02-16 14:29:53 [22140] [INFO] Booting worker with pid: 22140

And I get continuos error like this,

2014-02-16 14:29:53 [22140] [DEBUG] Ignoring EPIPE
Ignoring EPIPE
2014-02-16 14:29:53 [22140] [DEBUG] Ignoring EPIPE
Ignoring EPIPE
2014-02-16 14:29:57 [22140] [DEBUG] Ignoring EPIPE
Ignoring EPIPE

And worker starts again,

2014-02-16 14:32:44 [1267] [CRITICAL] WORKER TIMEOUT (pid:4993)
2014-02-16 14:32:44 [1267] [CRITICAL] WORKER TIMEOUT (pid:4993)
2014-02-16 14:32:44 [22276] [INFO] Booting worker with pid: 22276

Again Ignoring EPIPE error and this continues until I restart the gunicorn. And when I am getting this error I get 504 gateway error from nginx

s.m
  • 543
  • 1
  • 4
  • 8

1 Answers1

44

To fix this increase the timeout flag in Nginx,

In Nginx increase proxy_connect_timeout and proxy_read_timeout, you can add the following in nginx.conf file under the http directive. They default to 60s.

proxy_connect_timeout 300s;

proxy_read_timeout 300s;

Restart Nginx server. See nginx docs on timeouts.

If above fix doesn't work, then increase Gunicorn timeout flag in Gunicorn configuration, default Gunicorn timeout is 30 seconds.

--timeout 90

Gunicorn documentation about timeout

-t INT, --timeout INT 30 Workers silent for more than this many seconds are killed and restarted.

Generally set to thirty seconds. Only set this noticeably higher if you’re sure of the repercussions for sync workers. For the non sync workers it just means that the worker process is still communicating and is not tied to the length of time required to handle a single request.

Gunicorn Docs on Worker Timeouts

Hope this solves it.

radtek
  • 405
  • 4
  • 6
sreekanth
  • 541
  • 4
  • 6
  • 2
    This solution saved my life after I was looking for a solution all day. If you genuinely have a process that runs longer than 30s (which was my problem), then this is definitely the correct solution. – Alex P. Miller Mar 16 '15 at 22:51
  • Yes, even we have a scenario that runs longer than 30 seconds, hence we adopted the solution. Nice it helped. – sreekanth Mar 17 '15 at 12:14
  • We dont have such a scenario. There is a mininal traffic on site, but the workers timeout each day nearly at the same time. Then gets running after 1-2 mins. My setup is nginx - supervisor - gunicorn - django. I have timeout of 120 secs. – iamkhush Apr 15 '16 at 09:55
  • 1
    proxy_connect_timeout: "Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout **cannot usually exceed 75 seconds**." – deweydb Dec 06 '17 at 23:45
  • @iamkhush were you able to figure out the fix for this? I'm also facing this issue even when my application is idle. Gunicorn workers timeout daily and none of the solutions like increasing the timeout seem to work. – Ankit Jaiswal Nov 11 '19 at 13:28