Issue #957 new

_cpcgifs.FieldStorage() can throw a socket timeout error, which isn't handled correctly

Anonymous created an issue

Occasionally (more prevalent with HTTP POST requests coming from mobile Browsers with less reliable cellular connectivity), I'm running into a socket timeout error that isn't handled correctly. Here is the stack trace: {{{ Traceback (most recent call last): File "cherrypy/", line 600, in respond self.process_body() File "cherrypy/", line 718, in process_body keep_blank_values=1) File "cherrypy/", line 8, in init cgi.FieldStorage.init(self, *args, kwds) File "python/", line 519, in __init__ File "python/", line 640, in read_multi File "cherrypy/", line 8, in __init__ cgi.FieldStorage.__init__(self, *args, kwds) File "python/", line 521, in init File "python/", line 655, in read_single File "python/", line 677, in read_lines File "cherrypy/", line 31, in read_lines_to_outerboundary line = self.fp.readline(1<<16) File "cherrypy/wsgiserver/", line 204, in readline data = self.rfile.readline(size) File "cherrypy/wsgiserver/", line 1027, in readline data = self.recv(self._rbufsize) File "cherrypy/wsgiserver/", line 928, in recv return self._sock.recv(size) timeout: timed out }}}

Since this is a benign network connectivity issue, I think CP should gracefully handle the dropped request without logging the stack trace. I'm not sure of the best way to catch this, maybe something like this in process_body(): {{{ try: forms = _cpcgifs.FieldStorage(fp=self.rfile, headers=h, # FieldStorage only recognizes POST. environ={'REQUEST_METHOD': "POST"}, keep_blank_values=1) + except socket.error, e: + if e.args[0] == 'timed out': + raise cherrypy.HTTPError(408) + else: + raise except Exception, e: if == 'MaxSizeExceeded': # Post data is too big raise cherrypy.HTTPError(413) else: raise }}}

Matt Bendiksen

Reported by matt_cherrypy@perceptiveautomation

Comments (2)

  1. Log in to comment