Script timed out before returning headers: wsgi.py on elastic beanstalk

elastic beanstalk script timed out before returning headers
wsgiapplicationgroup elastic beanstalk
elastic beanstalk end of script output before headers
wsgi.conf elastic beanstalk
elastic beanstalk mod_wsgi
wsgipath elastic beanstalk
wsgi timeout
elastic beanstalk python

I'm trying to deploy a Django application to Elastic Beanstalk. When I visit the page it never loads. The logs say:

Script timed out before returning headers: wsgi.py

I can ssh into the server and run manage.py runserver and then curl 127.0.0.1:8000 from another terminal, which will return the page successfully. So I'm assuming it must be an issue with the Apache configuration that is set up as a part of Elastic Beanstalk.

Here is more of the logs:

[pid 15880] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[so:warn] [pid 15880] AH01574: module wsgi_module is already loaded, skipping
[auth_digest:notice] [pid 15880] AH01757: generating secret for digest authentication ...
[lbmethod_heartbeat:notice] [pid 15880] AH02282: No slotmem from mod_heartmonitor
[mpm_prefork:notice] [pid 15880] AH00163: Apache/2.4.9 (Amazon) mod_wsgi/3.4 Python/2.7.5       configured -- resuming normal operations
[core:notice] [pid 15880] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[:error] [pid 15881] /opt/python/run/venv/lib/python2.7/site-packages/numpy/oldnumeric/__init__.py:11: ModuleDeprecationWarning: The oldnumeric module will be dropped in Numpy 1.9
[:error] [pid 15881]   warnings.warn(_msg, ModuleDeprecationWarning)
[:error] [pid 15881] 
[core:error] [pid 15884] [client 10.248.110.45:58996] Script timed out before returning headers: wsgi.py

And my wsgi.py file:

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "aurora.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Any clues as to what could be causing this?

UPDATE:

I rebuilt my environment and ran into this issue again. I updated /etc/httpd/conf.d/wsgi.conf to include WSGIApplicationGroup %{GLOBAL} as mentioned here. I am using Scipy, Numpy, and GeoDjango (which uses GDAL). I know GDAL is not entirely thread safe and I'm not sure about the others but I'm assuming it was a thread safety issue.


UPDATE 8 FEB 2017

Previously my wsgi.conf was only using one process:

WSGIDaemonProcess wsgi processes=1 threads=15 display-name=%{GROUP}

I upped the processes to something more reasonable and haven't had any issues:

WSGIDaemonProcess wsgi processes=6 threads=15 display-name=%{GROUP}

This change along with the original addition of WSGIApplicationGroup %{GLOBAL} seems to have done the trick.

UPDATE 17 September 2015

I'm still occasionally running in to this issue. Usually, redeploying via eb deploy fixes the issue. It's hard to say what the underlying issue is.

Original Answer

I eventually got the project working but then tried creating an image to use for new instances, which reopened the problem. I'm not sure why it worked then stopped working but I rebuilt my custom AMI from scratch and then repushed my project. Turns out it was an issue in wsgi.py. The version I posted was actually the different from what was being deployed. For some reason another developer had put this in wsgi.py:

path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if path not in sys.path:
sys.path.append(path)

I removed this and it fixed the problem.

My advice for anyone having

Script timed out before returning headers: wsgi.py

is to check you wsgi.py file.

Script timed out before returning, Script timed out before returning headers: wsgi.py. Posted by: I'm trying to deploy a Django application to Elastic Beanstalk. When I visit the� Script timed out before returning headers: wsgi.py on elastic beanstalk 461 `pg_tblspc` missing after installation of latest version of OS X (Yosemite or El Capitan)


It certainly does seem like an issue with WSGI and Apache like you mentioned. One thing to double check is the .ebextensions file in your source directory.

There should be a config in there that specifies the WSGI information like the location of the application. You might also want to check your Django settings and run it locally with an Apache setup using WSGI.

You've probably already read the official documentation for WSGI and Django, but this might catch some simplistic things that you might have missed: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html#create_deploy_Python_django_update

Add mention of WSGI + GIL caveats, especially for Elastic Beanstalk , A /var/log/httpd/error_log full of Script timed out before returning headers: wsgi.py initially. Those were reduced by changing .ebextensions/wsgi.config to I have been trying to deploy my flask app on aws using their elastic beanstalk service but I havnt had any luck. 127.0.0.1:47210] Script timed out before


Just my 2 cents on a similar issue I faced.

I had a similar problem. It turned out to be that the script (which makes a DB insert/update/delete call) being executed from django application was waiting in a deadlock state for the lock on the table to be released. Once it was released, the code went through without this error. I never had to re-deploy my EB application.

  1. Make sure that you are not connected to the database through any other SQL client. If yes, query for any active locks. (In my case, I was connecting to redshift. Querying STV_LOCKS table lists the active locks).
  2. Check who is holding the locks. (In my case, it was my SQL client, connected to redshift, which executed a CUD operation, and since COMMIT was not issued, it was holding a pending write lock on the table).
  3. I issued a commit from my SQL client, and the lock was released. My EB code went through and there was no Script timed out error any more.

Apache/wsgi "Script timed out before returning headers", You could try to add a limit of requests after which the daemon processes are recycled (before an external process does it). This is done by adding the� Script timed out before returning headers: wsgi.py on elastic beanstalk; Request timed out - Request timed out; Django - End of script output before headers; Python: CGI update webpage before script exit; Apache: End of script output before headers


The fix for us was to add the WSGIApplicationGroup %{GLOBAL} setting as per Meistro's answer.

You'll want to ensure you edit your wsgi config by way of your .ebextensions/foobar.config file, so that the changes are permanent. See the .ebextensions config docs.

Add the following to your .ebextensions/foobar.config file:

files:
  "/etc/httpd/conf.d/wsgi_custom.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      WSGIApplicationGroup %{GLOBAL}

This will create (or overwrite) the contents of the /etc/httpd/conf.d/wsgi_custom.conf file with WSGIApplicationGroup %{GLOBAL}

Script timed out before returning headers: wsgi.py; Django app on , I'm trying to deploy a Django application to Elastic Beanstalk. When I visit the page it never loads. The logs say: Script timed out before returning headers:� [Mon Jan 23 10:06:51.550205 2017] [core:error] [pid 7331] [client 127.0.0.1:43790] script timed out before returning headers: application.py [Mon Jan 23 10:10:43.910014 2017] [core:error] [pid 7329] [client 127.0.0.1:43782] End of script output before headers: application.py. Есть идеи, почему это может быть?


I have tried above steps which can solve issue temporally. then I have done bellow steps:

  1. make "packages.config" file under ".ebextensions " folder and put following lines

    WSGIApplicationGroup: command: grep -rnw 'WSGIApplicationGroup' config.py || sed -i.bak '/LogFormat/ a WSGIApplicationGroup %%{GLOBAL}' config.py cwd: /opt/elasticbeanstalk/hooks

thanks for helps to made this who given suggestion for this type of error

I finally fixed. just read about apache mpm load module concept

I was changed the default load mode from apache preforker(my case) module which is depends on os.

find below location

location : /etc/httpd/conf.module.d/00-mpm*.

Enable worker module which depends our cases

LoadModule mpm_worker_module lib64/httpd/modules/mod_mpm_worker.so

once again thanks for who helped me.

Deploying a Django App to AWS Elastic Beanstalk – Real Python, Script timed out before returning headers: wsgi.py; Django app on elastic beanstalk All of the following are elastic beanstalk configs:. It also won't raise any errors; as it turns out the mechanism it uses to add the specified python-path to the site packages is with the Python site module, specifically site.adduserdir(). This method doesn't raise any errors if the directory is missing or can't be accessed, so mod_wsgi also doesn't raise any errors.


AWS Elastic Beanstalk, Let's look at how to deploy a Django App to AWS Elastic Beanstalk. a number of “gotchas” that exist when deploying to Amazon Beanstalk and RDS Be patient as this can take some time. And then you will have you WSGIPath set up correctly. Header append Vary User-Agent env=!dont-vary </IfModule> </ IfModule>. Elasticsearch DSL. Also check out elasticdsl - an R Script timed out before returning headers: wsgi.py on elastic beanstalk Amazon Elastic Beanstalk deploy


Flask and python-saml on Amazon Elastic Beanstalk – MIKAMAYHEM, The @user2752159's answer highlights the issue however I am going to add this to show how to overcome this issue in the context of AWS Beanstalk (ie. if a� Elastic Beanstalk uses this WSGI script to start the deployed app. We now finished the configuration of Django project for Beanstalk and can deactivate our virtual environment and move on to the deployment of our app onto AWS Elastic Beanstalk. Step 4. Deploying configured Django project to AWS using EB CLI.


Deploying a Django application to Elastic Beanstalk, As the time I'm writing the platform in use on my AWS EB instances is 64bit Python 2.7 and we are serving our website with apache and mod_wsgi and in the logs we can see Script timed out before returning headers . Deploying Django 2.x with Django Channels 2.x on AWS Elastic Beanstalk through either a reverse proxy server or a load balancer. Connecting Redis as the channel layer. Getting Apache and/or Daphne