Timeout error for flask app

78 views
Skip to first unread message

Aash

unread,
Apr 30, 2023, 12:05:17 AM4/30/23
to modwsgi
I am trying to host my Flask app on a Linux server. My app connects to an API and waits for a response. It is giving me this error.

[Sun Apr 30 05:57:30.091150 2023] [wsgi:error] [pid 524703:tid 140623501117184] [client someIp:62319] Timeout when reading response headers from daemon process 'webApp': /var/www/webApp/webapp.wsgi, referer: http://serverIP/

My conf file looks like this:

  1. <VirtualHost *:80>
  2.     ServerName serverIp
  3.     ServerAdmin em...@mywebsite.com

  4.     WSGIDaemonProcess webApp processes=4 threads=5 maximum-requests=1000 request-timeout=600
  5.     WSGIProcessGroup webApp

  6.     WSGIScriptAlias / /var/www/webApp/webapp.wsgi process-group=webApp application-group=%{GLOBAL}

  7.     <Directory /var/www/webApp/webApp/>
  8.         Order allow,deny
  9.         Allow from all
  10.     </Directory>

  11.     Alias /static /var/www/webApp/webApp/static
  12.     <Directory /var/www/webApp/webApp/static/>
  13.         Order allow,deny
  14.         Allow from all
  15.     </Directory>

  16.     ErrorLog ${APACHE_LOG_DIR}/error.log
  17.     LogLevel warn
  18.     CustomLog ${APACHE_LOG_DIR}/access.log combined
  19. </VirtualHost>
The error on user-side is 
Gateway Timeout

The gateway did not receive a timely response from the upstream server or application.




Graham Dumpleton

unread,
Apr 30, 2023, 12:10:01 AM4/30/23
to mod...@googlegroups.com
How long does it usually take for the remote API to respond? Does it always respond quickly, or can it take a very long time? Does this error occur on every request, or only after your web application has been running for a while?

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/94c43590-df3c-4a93-8cd9-d2afb965a631n%40googlegroups.com.

Aash

unread,
Apr 30, 2023, 12:18:47 AM4/30/23
to modwsgi
Hello Graham, Thanks for the quick response.

The API response depends on how many items are sent in a batch so for a long list it can take a long time (It is taking a list of domains and returns a list). I am using the Python Requests library and requests.post to call the API. 
This error occurs only when there is a long list which might need a minute or two to get response from the API. The error occurs on all the requests that are having longer lists. 

Graham Dumpleton

unread,
Apr 30, 2023, 12:21:15 AM4/30/23
to mod...@googlegroups.com
What is the Timeout directive set to in your main Apache configuration?

Aash

unread,
Apr 30, 2023, 12:27:53 AM4/30/23
to modwsgi
I never changed it. It shows 300. Should I make it to 600?

Graham Dumpleton

unread,
Apr 30, 2023, 12:34:52 AM4/30/23
to mod...@googlegroups.com
Having to set these timeouts to be very large values is generally indicative of a poor design.

For these sorts of long running operations you are usually better of using a background task queuing system like Celery to handle running of the job. Your front end then just queues the job and polls to see if the task is finished and get the response.

In the worst case for these very long running requests a synchronous type web system like WSGI may not be a good idea and you are better off using an async web server.

That all said, likely what is happening is that because Timeout is 300, the Apache child process is giving up on waiting for a response from the mod_wsgi daemon process before request-timeout could even kick in.

You can try overriding socket-timeout option on WSGIDaemonProcess to a larger value that 300 (inherited from Timeout), but as I said, using large timeouts like this is generally not a good idea.

Graham

Aash

unread,
Apr 30, 2023, 12:53:29 AM4/30/23
to modwsgi
I see, thank you Graham for the explanation.

Regards,
Ash

Reply all
Reply to author
Forward
0 new messages