Hide Forgot
Created attachment 564798 [details] Proposed patch Description of problem: The worker threads in CherryPy's WSGI server can die off due to unhandled EPIPE exceptions. Version-Release number of selected component (if applicable): python-cherrypy2-2.3.0-11.el6.noarch How reproducible: Not 100% of the time, as it seems to be timing sensitive (EPIPE has to occur in the middle of a buffered write). But it can be reproduced with some looping. Steps to Reproduce: Minimal CherryPy server: import pkg_resources pkg_resources.require('CherryPy==2.3.0') import cherrypy class Root(object): def index(self): return '.' * 1000 index.exposed = True cherrypy.tree.mount(Root()) cherrypy.server.start() Client program which triggers EPIPEs in the server: import socket, time while True: s = socket.socket() s.connect(('localhost', 8080)) f = s.makefile() f.write('GET / HTTP/1.0\r\n\r\n') f.flush() s.close() # close without reading, to trigger EPIPE Start the server, and then run the client and watch it kill the server. Actual results: Each worker thread will eventually die off with an exception like this: Exception in thread CP WSGIServer Thread-9: Traceback (most recent call last): File "/usr/lib64/python2.6/threading.py", line 532, in __bootstrap_inner self.run() File "/usr/lib/python2.6/site-packages/CherryPy-2.3.0-py2.6.egg/cherrypy/_cpwsgiserver.py", line 252, in run request.terminate() File "/usr/lib/python2.6/site-packages/CherryPy-2.3.0-py2.6.egg/cherrypy/_cpwsgiserver.py", line 211, in terminate self.wfile.close() File "/usr/lib64/python2.6/socket.py", line 276, in close self.flush() File "/usr/lib64/python2.6/socket.py", line 303, in flush self._sock.sendall(buffer(data, write_offset, buffer_size)) error: [Errno 32] Broken pipe If you leave the above client program running for a few more seconds you will eventually see "Too many open files" in the server, which is because it is accepting connections but there are no worker threads left to handle them. Expected results: EPIPE is ignored and the server keeps on going. Additional info: Patch attached.
If somebody has time to look at this, feel free to apply. I'm going to be swamped with work until after PyCon (March 16th or so). The analysis looks good. A brief look at the code looks good as well but I haven't dived in to know if there is a better place to check for the error. Please don't let that stop you from applying the patch, though, if you have time to check that this solves the problem and doesn't cause any regressions when you have it deployed to the real world.
python-cherrypy2-2.3.0-17.el6 has been submitted as an update for Fedora EPEL 6. https://admin.fedoraproject.org/updates/python-cherrypy2-2.3.0-17.el6
Sorry I lost track of this. Your patch has been added to this build. See if it solves the problem. Builds are also in progress for F16 through F18.
Oh, and Felix, if you're still working on a new upstream release of cherrypy2, probably want to take a look at that patch too. :-)
Package python-cherrypy2-2.3.0-17.el6: * should fix your issue, * was pushed to the Fedora EPEL 6 testing repository, * should be available at your local mirror within two days. Update it with: # su -c 'yum update --enablerepo=epel-testing python-cherrypy2-2.3.0-17.el6' as soon as you are able to. Please go to the following url: https://admin.fedoraproject.org/updates/FEDORA-EPEL-2012-6466/python-cherrypy2-2.3.0-17.el6 then log in and leave karma (feedback).
python-cherrypy2-2.3.0-17.el6 has been pushed to the Fedora EPEL 6 stable repository. If problems still persist, please make note of it in this bug report.