﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
10046	ModPythonHandler class should check for IOError when writing response	Eric Woudenberg	nobody	"Apache was reporting occasional 500 errors of this form:

{{{ 
64.158.138.84 - - [15/Jan/2009:21:21:02 +0000] ""GET /feeds/recordings/ HTTP/1.1"" 500 17156 ""-"" ""BlogPulseLive (support@blogpulse.com)"" 256 20528 220012 
}}}

Although Django itself was not emailing any errors, the Apache error_log contained:

{{{ 
mod_python (pid=6859, interpreter='dharmaseed.org', phase='PythonHandler', handler='django.core.handlers.modpython'): Application error
ServerName: 'dharmaseed.org'
DocumentRoot: '/htdocs'
URI: '/feeds/teacher/175/'
Location: '/feeds'
Directory: None
Filename: '/htdocs'
PathInfo: '/feeds/teacher/175/'
Traceback (most recent call last):
  File ""/usr/lib/python2.5/site-packages/mod_python/importer.py"", line 1537, in HandlerDispatch\n    default=default_handler, arg=req, silent=hlist.silent)
  File ""/usr/lib/python2.5/site-packages/mod_python/importer.py"", line 1229, in _process_target\n    result = _execute_target(config, req, object, arg)
  File ""/usr/lib/python2.5/site-packages/mod_python/importer.py"", line 1128, in _execute_target\n    result = object(arg)
  File ""/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py"", line 228, in handler\n    return ModPythonHandler()(req)
  File ""/usr/lib/python2.5/site-packages/django/core/handlers/modpython.py"", line 220, in __call__\n    req.write(chunk)
IOError: Write failed, client closed connection.
python_handler: Dispatch() returned non-integer.
}}}

It gets an error writing the socket. (Perhaps it was closed prematurely by the remote side?). The remedy is to explicitly check for error:

{{{
        try:
            for chunk in response:
                req.write(chunk)
        except IOError:          # Explicitly ignore IOError if it occurs.
            pass
        finally:
            response.close()
}}}

Which is done in the attached patch.
"	Bug	closed	HTTP handling	1.1	Normal	wontfix		bricetebbs@… dnordberg+django@… andreazzini+webmaster@… andre.cruz+djangobg@… Shaun Cutts Almad	Design decision needed	1	0	0	0	0	0
