Django and mod_wsgi issue: "Script timeout before returning headers: wsgi.py"

I am running a Django app on Apache 2.4.7 with mod_wsgi 3.4. All setup is on the EC2 ubuntu instance. Since I deployed the app, the server has 504/503 errors every two days with this message in the logs:

Script timed out before returning headers: wsgi.py

I've searched extensively, but all I can conclude is a memory leak somewhere? I can't figure out what's actually going wrong as my Django installation is pretty vanilla. This is the important part of my conf file:

WSGIScriptAlias / /home/ubuntu/projects/appname/app/app/app/wsgi.py WSGIDaemonProcess app python-path=/home/ubuntu/projects/appname/app user=ubuntu WSGIProcessGroup app WSGIApplicationGroup %{GLOBAL}

Could it be from some third party library? The only add-ons I have installed are ImageMagick and exiftool, the latter of which is not used. Is there anything else I can do for debugging?

+3


source to share


1 answer


Does your application specify any backend services?

If you get 503/504 and this message then it is usually indicated that your code is either hanging on backend services or that your code is blocking unlimited threads while blocking threads.

Thus, basically all request streams become busy and wasted.



If they didn’t provide such an ancient version of mod_wsgi, then newer versions at least have better options to deal with such a problem in your application and repair it automatically, as well as log information to help you figure out why.

For such an older version, you can set the "inactivity-time" of WSGIDaemonProcess to "60" as the recovery method, but this will also restart your application after 60 seconds if it does not receive any requests, which may in itself not be ideal for some applications. In newer versions, the idle timeout is separated from the concept of a request timeout.

+1


source







All Articles