mod_wsgi fails to log python errors

Bug #908605 reported by Phil Stone
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
mod-wsgi (Ubuntu)
Confirmed
Medium
Unassigned

Bug Description

mod_wsgi based python apps that generate python errors, like divide by zero, should send a 500 error to the browser and log the python errors in the applications' log.

In Ubuntu 11.10 a regression was introduce where the Apache VirtualHost must be specified as *:80 for this expected behavior to still work. Anything else sends the 500 error to the browser, but leaves nothing in the apache log file.

Here are the 2 files needed to reproduce the problem...
To reproduce you also need an entry in /etc/hosts for www.hello.loc to be 127.0.0.1,
and an otherwise working apache server.

--- The standard mod_wsgi Hello World App, modifed to force a divide by zero error... ---

#!/usr/bin/python

def application(environ, start_response):

    a = 5/0 # This line added to induce a deliberate error. Hide this line to always see Hello World! in browser.

    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

--- The Apache Configuration file for this same application ---

WSGIRestrictEmbedded On

<VirtualHost 127.0.0.1:80>

    ServerName www.hello.loc

    WSGIProcessGroup hello.loc
    WSGIDaemonProcess hello.loc processes=1 threads=10 display-name=%{GROUP}
    WSGIScriptAlias / /www/hello/website.py process-group=hello.loc application-group=${GLOBAL}

    LogLevel warn
    ErrorLog /www/hello/logs/error.log
    CustomLog /www/hello/logs/access.log combined

</VirtualHost>

--- NOTES ---

The 2 files given above are SUPPOSED to generate an internal error to the browser (a 500 error)
AND log into the error log the python traceback showing the line and file where the divide by zero
error happened.

It does not work because of the 127.0.0.1 in the VirtualHost...

Also broke are Named Virtual Hosts of any form, as in...

<VirtualHost local>

The work around is to use "*" instead, as in...

<VirtualHost *:80>

I found this bug on an upgrade of Ubuntu Server to 11.10.

Note that the form that works, <VirtualHost *:80> serves the site on all IP addresses on a
server. This is the "toy" form of this command. Real servers are often multi-homed.
The parameter on the Virtual host when not *:80 is supposed to indicate the IP or named server that
is being used.

NOTE... ONLY ERROR LOGGING is impacted by this bug, NOT normal display.

A website impacted by this bug, especially after a system upgrade to 11.10, will serve
"Internal Server Errors" to client browsers and NOT log the error to the error logs
for discovery later by an administrator.

(As I found out to my trouble on a much, much bigger system than this example.)

Technically the work-around given above is a potential security issue depending on the networking
involved, so be careful if you're reading this and hacking your server to get it working again.

Dave Walker (davewalker)
Changed in mod-wsgi (Ubuntu):
importance: Undecided → Medium
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in mod-wsgi (Ubuntu):
status: New → Confirmed
Revision history for this message
TJ (tj) wrote :

The upstream bug report relating to this is:

http://code.google.com/p/modwsgi/issues/detail?id=276&can=1&sort=-id

Unfortunately it is impossible to add it to this bug report since mod_wsgi is incorrectly linked to PyLucid as the upstream source.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.