13

I recently migrated a python django application from a debian system to a redhat enterprise distribution. The application is hosted using httpd, mod_wsgi and running in a venv in an daemon process. On large requests I now get following error message in the log file:

"Truncated or oversized response headers received from daemon process" 

I have never experienced anything like this and Google is not the key here as well. I checked configuration of apache, but no config is related to response headers in there.

My httpd.conf configuration looks like this ( pretty standard):

WSGIPassAuthorization On
WSGIScriptAlias / /var/www/myapp/wsgi.py
WSGIDaemonProcess my.name python-path=/path/to/myapp/:/path/to/venv/lib/python2.7/site-packages display-name=%{GROUP}
WSGIProcessGroup my.name

Does any Guru have a hint in which direction I should look?

kartopete
  • 157
  • 1
  • 1
  • 7

10 Answers10

8

We recently ran into this issue, and after days of vigorous ugoogleizing and massive headache, we discovered that we were using psycopg2-binary as our database connector dependency (I know, newbs)! It states right in their documentation not to use the package in a production environment.

We did add all the other proposed answers such as adding 'WSGIApplicationGroup %{GLOBAL}' to our settings (which we kept), but all of them alone and together didn't solve the issue.

We also found that other C libraries like numpy, cause issues.

Hope this helps someone some day.

Django Webfaction 'Timeout when reading response headers from daemon process'

http://initd.org/psycopg/docs/install.html#prerequisites

Paul Tuckett
  • 1,023
  • 11
  • 14
  • 3
    Thanks... this worked for me. uninstalled `psycopg2-binary` and installed `psycopg2` – suhailvs Jul 12 '19 at 11:08
  • this should be accepted answer. worked for me as well! – Adrian Chrostowski Aug 21 '19 at 08:27
  • 2
    Reinstalling `psycopg2-binary` worked for me. Thanks! – palawer Aug 21 '19 at 19:12
  • 1
    Just doing 'pip install psycopg2' requires that prerequisites be installed by 'apt' first, but then you'll have a working psycopg2 WITHOUT psycopg2-binary which causes this bewildering problem. See https://www.psycopg.org/docs/install.html#prerequisites – Ron Feb 12 '20 at 23:18
  • I had this error come in random (probably because of numpy) and crash my site. I just did what you said and I don't know if it works. Do you have any idea on how I could try to reproduce the error ? – Sam May 04 '20 at 08:18
  • @Sam I don't fully understand your question. You got the error, so you implemented the fix, and you don't know if it works, but you want to reproduce the error? – Paul Tuckett Feb 11 '21 at 13:05
6

The code used from Apache by mod_wsgi applies a limit on the size of a single response header returned from mod_wsgi daemon mode processes. This would result in a really cryptic error message from Apache which didn't at all point to the problem. From memory the previous error was:

Premature end of script headers

The size limit was also hard coded in Apache and couldn't be changed. This has caused problems for some Python web applications such as Keystone in OpenStack which generates very large authentication headers.

In mod_wsgi 4.1+, the reliance on the Apache code has been removed and the limit is now configurable. The error message is also more specific as you have seen.

The default maximum header size for what is returned from mod_wsgi daemon mode, that is header name and value, is about 8192 bytes. You can override this by using the header-buffer-size option to WSGIDaemonProcess.

Can you indicate what application and what header was so large that the limit was reached as would like to know what other Python web applications besides Keystone are generating such large headers if is a commonly used application.

A second possibility, deriving from the 'truncated' reference in that message, is that your mod_wsgi daemon process crashed. You don't say though that you saw a 'Segmentation fault' or similar message indicating that a crash occurred. Check for that and if there are other messages in the error log at the time, then indicate what they were and can look at that as the primary problem.

mlissner
  • 17,359
  • 18
  • 106
  • 169
Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • I will check this tomorrow morning. The problem is caused by Django, I grab svg-xml from some statistical graphs on the webpage and push them to django (1.6.5), where I use Cairo and xhtml2pdf to convert them to png files and put into a pdf file, which is the response. I have run this app on a WSGIDaemonProcess many times before and never had problems. First time this happens when I test it on a new RHEL 6 server. Python is 2.7.3 and Apache is 2.2. – kartopete Jul 20 '14 at 14:46
  • OK. No success! I increased header-buffer-size=32768 first to approx. 16000 and now 32768. No changes. Restarted apache, removed .pyc files of wsgi.py and so on. No success. For more info, here is the wsgi.py I use: – kartopete Jul 20 '14 at 15:11
  • import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application() – kartopete Jul 20 '14 at 15:19
  • Sorry, my fault. I guess this is an success. I didn't close the app on restart, so the process was not reloaded. As far as I see it works. Let me test tomorrow, then I give the OK to mark as resolved. Thank you very much Graham. Saved me a hell of a time.Cheers Kartopete – kartopete Jul 20 '14 at 15:25
  • If this is the response header size, can you clarify what the header was for that was so large. – Graham Dumpleton Jul 20 '14 at 20:41
  • Hang on. I guess it was false alarm yesterday. I checked and I have the same problem. I need more tim eon this. As well I need to see how to print the response header as the one seen in the browser is coming from an internal server error page from django, regardless on the debug mode of django. – kartopete Jul 21 '14 at 08:05
  • 3
    Just go set 'WSGIApplicationGroup %{GLOBAL}' and see if the issue goes away. It is more likely the process is crashing and you just aren't noting the error message indicating that from the Apache error logs. – Graham Dumpleton Jul 21 '14 at 10:25
  • Also make sure you go read http://code.google.com/p/modwsgi/wiki/DebuggingTechniques – Graham Dumpleton Jul 21 '14 at 10:25
  • @GrahamDumpleton where do you add "WSGIApplicationGroup %{GLOBAL}" in the config file? Does the order matter? – retro_coder Dec 14 '19 at 08:24
1

Turned out to be not the actual problem. The problem was lying deeper, as I changed Cairo to CairoCffi and the RSVG-Handler couldn't deal with the Context-Object coming from Cffi. No my actuall problem is having an up-to-date python lib that allows me to convert svg into png. Using svg2png from CairoSVG isn't working for me. I get an

cairo returned CAIRO_STATUS_NO_MEMORY: out of memory

Error, which I'm sure of, that it does not tell the truth again and the problem lies somewhere else. But lets see.

kartopete
  • 157
  • 1
  • 1
  • 7
1

I had an issue with this in CentOS 7 server when deploying Django using httpd with mod_wsgi 4.5.4. I had to revert back to using mod_wsgi 4.3.2 which solved my problem.

Morfat Mosoti
  • 172
  • 2
  • 9
  • 2
    Are you setting the application group to ``%{GLOBAL}``? It is more likely your daemon mode process is crashing. See http://modwsgi.readthedocs.io/en/develop/user-guides/application-issues.html#python-simplified-gil-state-api – Graham Dumpleton Aug 13 '16 at 13:38
1

I have installed filebeat which changed my ssl version so that psycopy2 needs to be updated and the error was Truncated or oversized response headers received from daemon process

Do the following:-

Uninstall your psycopy2 package using pip. I am using pip3 because my python version is 3.6.8

sudo pip3 uninstall psycopg2

Reinstall psycopy2 using pip.

sudo pip3 install psycopg2

Before psycopg2-2.7.4 now psycopg2-2.8.3

Rajesh
  • 11
  • 4
0

I suddenly had this same problem after an update. The next update fixed the problem... I run arch, as of the date of this post, the WSGI version in repo works.

Luke Dupin
  • 2,275
  • 23
  • 30
0

I had the same error message "Truncated or oversized response headers received from daemon process '...': /var/www/dev.audiocont.com/index.wsgi" in my Django project (without any other error message).

My error was that I changed the virtual environment and forgot to adapt the Apache settings "dev.conf" to the new venv path.

Harald Mandl
  • 91
  • 1
  • 8
0

Change Deadlock time out in httpd.conf I tried everything ,none of the answer work for me .Then i change the deadlock timeout and everything works fine now .Server Goes in to idle state for long processing just change the deadlock timeout.

ashu
  • 167
  • 2
  • 12
0

I got into the same problem "Truncated or Oversized Response Headers".

I Resolved it by adding,

"WSGIDaemonProcess test user=apache group=apache processes=1 display-name=%{GROUP} header-buffer-size=65536" 

in app.conf/httpd.conf depends upon your configuration file.

Based on your server's RAM size change the Processes and header-buffer-size. Default is header-buffer-size is 65536

HatLess
  • 10,622
  • 5
  • 14
  • 32
Indhumathi
  • 11
  • 2
0

For me SQLite turned out to be the problem.

I migrated a Django application with SQLite, on a new server, and this error started appearing, and the HTTP requests hanging.

I manage to solve the issue with:

WSGIApplicationGroup %{GLOBAL}'

But, I wanted to get to the bottom of the problem, as this application was not using any different python modules than other applications on the same server.

I realized that the only difference is the SQLite database, and after migrating from SQLite to Postgres, the problem went away.

In the past, I've had other grievances with using Django with SQLite, so I would advise against using SQLite for anything that needs to go into production.

Martin Taleski
  • 6,033
  • 10
  • 40
  • 78