Question

[CRITICAL] WORKER TIMEOUT - How can i reach gunicorn timeout settings?

I’m getting a “[CRITICAL] WORKER TIMEOUT” error when I try to perform an action by clicking a button on my site deployed on DigitalOcean. What should I do? Maybe i can solve with gunicorn settings but i can not find anything about gunicorn.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
June 21, 2023

Heya @62dfd9df520c436686e71aa8cfb655,

The [CRITICAL] WORKER TIMEOUT error message from Gunicorn typically means that your web application is taking too long to respond to a request. In other words, the worker process is taking longer than the configured timeout duration to complete its work.

Here’s what you can do to diagnose and hopefully fix this issue:

Increase Gunicorn timeout setting: You may increase the timeout duration for Gunicorn workers to respond. This can be useful if your application often takes longer than 30 seconds (the default) to process requests. The -t or --timeout flag can be used to set a higher value. For instance, to set the timeout to 60 seconds, your command to start Gunicorn might look like:

gunicorn myproject.wsgi:application --timeout 60

Note that this is a band-aid solution and it’s usually better to try and improve the performance of your application, or offload long running tasks to a task queue or a background job system.

Enable Gunicorn’s debug mode: Running Gunicorn with the --debug flag will enable debug logging. This might help you figure out what’s causing the worker processes to take too long to respond. Keep in mind that this mode should only be used for debugging and not in production. Example:

gunicorn myproject.wsgi:application --debug

Check your application code: Inspect your application code to see if there are any long running or blocking tasks that might be causing the timeout. This might be a database query that’s taking too long, or a third-party API that your app is waiting on.

Async Workers: If your app handles a lot of I/O bound tasks (like network requests), consider using Gunicorn’s asynchronous worker types. Gunicorn offers worker types based on greenlets (gthread), and coroutines (gevent). Here’s an example of how to use the gthread worker type with a thread count of 2:

gunicorn myproject.wsgi:application -k gthread -w 3 --threads 2

Resource Constraints: Ensure that your server has enough resources (CPU, Memory) to handle the load. If your application is resource-intensive, you might need to upgrade your server.

Remember to make these changes in your Gunicorn configuration file or your service configuration if you’re using something like systemd or Supervisor to manage your Gunicorn process.

The optimal solution will depend on your specific situation, the nature of your application, and the resources available to you.

Additionally, depending on what you are using either Nginx or Apache, check the error logs there, they will give you more information on the matter.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel