Ticket #734 (defect)
Opened 10 months ago
Last modified 4 months ago
error "Connection reset by peer"
Status: closed (toolfix)
| Reported by: | Carsten Grohmann <carstengrohmann.gmx.de> | Assigned to: | fumanchu |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.1 |
| Component: | CherryPy code | Keywords: | |
| Cc: |
I've got an exception during running CherryPy. The exception was logged using the internal error handler.
Shouldn't be this exception catched?
Installed components:
- CherryPy 3.0.2
- Python 2.5.1
Error message:
File "/usr/local/python2.5/lib/python2.5/site-packages/cherrypy/_cprequest.py", line 547, in respond
self.process_body()
File "/usr/local/python2.5/lib/python2.5/site-packages/cherrypy/_cprequest.py", line 650, in process_body
keep_blank_values=1)
File "/usr/local/python2.5/lib/python2.5/site-packages/cherrypy/_cpcgifs.py", line 8, in __init__
cgi.FieldStorage.__init__(self, *args, **kwds)
File "/usr/local/python2.5/lib/python2.5/cgi.py", line 532, in __init__
self.read_urlencoded()
File "/usr/local/python2.5/lib/python2.5/cgi.py", line 637, in read_urlencoded
qs = self.fp.read(self.length)
File "/usr/local/python2.5/lib/python2.5/socket.py", line 309, in read
data = self._sock.recv(recv_size)
error: (104, 'Connection reset by peer')
Change History
10/16/07 08:14:41: Modified by Carsten Grohmann
10/16/07 08:28:13: Modified by Carsten Grohmann
Or use the KISS way:
--- _cprequest.py.old 2007-10-16 14:43:16.000000000 +0200
+++ _cprequest.py 2007-10-16 15:24:41.000000000 +0200
@@ -1,6 +1,7 @@
import Cookie
-import os
+import errno
+import socket
import sys
import time
import types
@@ -10,6 +11,8 @@
from cherrypy._cperror import format_exc, bare_error
from cherrypy.lib import http
+socket_errors_to_ignore = ("ECONNRESET",)
+
class Hook(object):
"""A callback and its metadata: failsafe, priority, and kwargs."""
@@ -555,6 +558,10 @@
inst.set_response()
self.hooks.run('before_finalize')
cherrypy.response.finalize()
+ except socket.error, e:
+ error_name = errno.errorcode.get(e.args[0])
+ if error_name not in socket_errors_to_ignore:
+ raise
finally:
self.hooks.run('on_end_resource')
except self.throws:
02/24/08 01:15:05: Modified by fumanchu
- owner changed from rdelon to fumanchu.
- status changed from new to assigned.
- milestone set to 3.1.
Trapping the socket errors may need to be done, but the application layer (_cprequest) is definitely not the place to do it--it should be handled completely within wsgiserver.py, perhaps with an rfile wrapper.
03/07/08 14:40:16: Modified by fumanchu
- status changed from assigned to closed.
- resolution set to toolfix.
This can be done in 3.1 by changing Request.throws and _cpwsgi.AppResponse?.throws to include socket.error:
cherrypy._cprequest.Request.throws = (KeyboardInterrupt, SystemExit, cherrypy.InternalRedirect, socket.error) cherrypy.wsgi.AppResponse.throws = (KeyboardInterrupt, SystemExit, socket.error)


The fix could be like the socket handling inside the wsgi server. As main difference a single error will be caught currently.
The imported and unused module os will be removed.
--- _cprequest.py.old 2007-10-16 14:43:16.000000000 +0200 +++ _cprequest.py 2007-10-16 15:11:12.000000000 +0200 @@ -1,6 +1,7 @@ import Cookie -import os +import errno +import socket import sys import time import types @@ -10,6 +11,14 @@ from cherrypy._cperror import format_exc, bare_error from cherrypy.lib import http +socket_errors_to_ignore = [] +# Not all of these names will be defined for every platform. +for _ in ("ECONNRESET",): + if _ in dir(errno): + socket_errors_to_ignore.append(getattr(errno, _)) +# de-dupe the list +socket_errors_to_ignore = dict.fromkeys(socket_errors_to_ignore).keys() + class Hook(object): """A callback and its metadata: failsafe, priority, and kwargs.""" @@ -555,6 +564,10 @@ inst.set_response() self.hooks.run('before_finalize') cherrypy.response.finalize() + except socket.error, e: + error_number = e.args[0] + if error_number not in socket_errors_to_ignore: + raise finally: self.hooks.run('on_end_resource') except self.throws: