Bug 795984

Summary: CherryPy WSGI server does not handle EPIPE
Product: [Fedora] Fedora EPEL Reporter: Dan Callaghan <dcallagh>
Component: python-cherrypy2Assignee: Toshio Ernie Kuratomi <a.badger>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: el6CC: a.badger, fschwarz, lmacken, mbacovsk
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-08-08 18:29:55 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
Proposed patch none

Description Dan Callaghan 2012-02-21 23:29:04 UTC
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.

Comment 1 Toshio Ernie Kuratomi 2012-02-23 16:07:01 UTC
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.

Comment 2 Fedora Update System 2012-07-20 21:48:28 UTC
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

Comment 3 Toshio Ernie Kuratomi 2012-07-20 21:53:14 UTC
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.

Comment 4 Toshio Ernie Kuratomi 2012-07-20 21:57:35 UTC
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. :-)

Comment 5 Fedora Update System 2012-07-21 00:20:59 UTC
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).

Comment 6 Fedora Update System 2012-08-08 18:29:55 UTC
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.