我也有这个例外。在Apache错误日志文件中,我看到以下内容:
[Wed Aug 17 08:30:45 2011] [error] [client 10.114.48.206] (70014)End of file found: mod_wsgi (pid=9722): Unable to get bucket brigade for request., referer: https://egs-work/modwork/beleg/188074/edit/[Wed Aug 17 08:30:45 2011] [error] [client 10.114.48.206] mod_wsgi (pid=3572): Exception occurred processing WSGI script '/home/modwork_egs_p/modwork_egs/apache/django_wsgi.py'.[Wed Aug 17 08:30:45 2011] [error] [client 10.114.48.206] IOError: failed to write data
版本:
apache2-prefork-2.2.15-3.7.x86_64apache2-mod_wsgi-3.3-1.8.x86_64 WSGIDaemonProcess with threads=1mod_ssl/2.2.15Linux egs-work 2.6.34.8-0.2-default #1 SMP 2011-04-06 18:11:26 +0200 x86_64 x86_64 x86_64 GNU/LinuxopenSUSE 11.3 (x86_64)
首先我很困惑,因为最后一行“无法写入数据”不适合django代码“加载发布数据”。但是我想django想要向客户写一个错误页面。但是客户端已取消tcp连接。现在,http 500页面无法写入客户端。
客户端在发送请求之后并获得响应之前已断开连接:
- 用户关闭浏览器或导航到其他页面。
- 用户按下重新加载按钮。
我只在POST请求(而不是GET)中看到了这一点。如果使用POST,则Web服务器至少会读取两次:第一个获取标头,第二个获取数据。第二次读取失败。
很容易复制:
插入一些在第一次访问request.POST之前等待的代码(请确保没有中间件在time.sleep()之前访问request.POST):
def edit(request): import time time.sleep(3) #.....
现在进行一次大型POST(例如文件上传)。我不知道Apache缓冲区的大小。但是5 MB应该足够了。当浏览器显示沙漏时,浏览到另一个页面。浏览器将取消该请求,并且异常应在日志文件中。
这是我的中间件,因为我不想在我们的日志文件中获得上述回溯:
class HandleExceptionMiddleware: def process_exception(self, request, exception): if isinstance(exception, IOError) and 'request data read error' in unipre(exception): logging.info('%s %s: %s: Request was canceled by the client.' % ( request.build_absolute_uri(), request.user, exception)) return HttpResponseServerError()


