1

I have a webApp i've been working on and I noticed that every once in a while I will see an error of "Exception in thread CP Server Thread-*" where * = random thread number.This error will occur occasionally and eventually will lock up the web server, preventing it from responding to requests.

I was able to reproduce the same issue with a default "hello World" webPy application using CherryPy to support the SSL.

import web
from web.wsgiserver import CherryPyWSGIServer

# GLOBALS
CherryPyWSGIServer.ssl_certificate = "/.ssl/fpi.crt"
CherryPyWSGIServer.ssl_private_key = "/.ssl/server.key"

urls = (
    '/(.*)', 'Hello',
    )

app = web.application(urls, globals())

class Hello:
    def GET(self, name):
        return 'Hello World'

if __name__ == "__main__":
    app.run()

The Error is:

73.220.196.76:63982 - - [27/Nov/2018 06:56:50] "HTTP/1.1 GET /" - 200 OK
73.220.196.76:63982 - - [27/Nov/2018 06:56:50] "HTTP/1.1 GET /favicon.ico" - 200 OK
Exception in thread CP Server Thread-9:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/__init__.py", line 1375, in run
    conn.communicate()
  File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/__init__.py", line 1269, in communicate
    format_exc())
  File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/__init__.py", line 811, in simple_response
    self.conn.wfile.sendall("".join(buf))
  File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/ssl_pyopenssl.py", line 111, in sendall
    *args, **kwargs)
  File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/ssl_pyopenssl.py", line 61, in _safe_call
    return call(*args, **kwargs)
  File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/__init__.py", line 913, in sendall
    bytes_sent = self.send(data)
  File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/ssl_pyopenssl.py", line 115, in send
    *args, **kwargs)
  File "/home/brian_barnes/.local/lib/python2.7/site-packages/web/wsgiserver/ssl_pyopenssl.py", line 77, in _safe_call
    raise socket.error(errnum)
error: -1

Environment: Ubuntu 18.04.1 LTS Python 2.7.15rc1 web.py: 0.39

Has anyone seen an issue like this or know what could be causing it. When reading on webpy.org. It appears this was an issue with version 0.36, but should be good with 0.37. I've thought about going to 0.40 but hesitant as it is still in dev.

5
  • It's probably because of pyopenssl. try out built-in ssl adapter. Commented Nov 28, 2018 at 0:02
  • Not helpful perhaps, but I've been running web.py 0.38 for years like this without problem (Ubuntu 14 & 16.. not tried 18). No problem with provided CherryPyWSGIServer. What is value of errnum? That won't be -1. Try catching exception socket.error to look at the details (See documentation on socket.error).
    – pbuck
    Commented Nov 29, 2018 at 22:47
  • Upstream CherryPy's WSGI server (Cheroot) has a number of errors which are ignored for SSL connections, but web.py seems to vendor that and thus not receive any updates/fixes. Commented Dec 10, 2018 at 19:37
  • I've been trying to get to the bottom of this for a long time and thought I was the only one seeing it
    – mwag
    Commented Mar 5, 2019 at 1:54
  • @webKnajZ not sure that's the issue, I see same issue using import cherrypy
    – mwag
    Commented Mar 5, 2019 at 2:46

1 Answer 1

0

This is probably not a proper fix but I did the following hack and the issue is no longer showing up for me. I am still looking for a better solution-- maybe throwing out CherryPy altogether-- but until then:

====> in def _safe_call in ssl_pyopenssl.py: replace

raise socket.error(errnum)

with

#### raise socket.error(errnum)
import sys
sys.stderr.write('===> ssl_pyopenssl: ignoring socket error' + str(errnum) + '\n')
return ""
####

along with similar patches for raise socket.error(-1) and raise wsgiserver.FatalSSLAlert(*e.args)

====> in def sendall in wsgiserver2.py: insert 2 lines as follows:

bytes_sent = self.send(data)
### insert the below two lines
if not bytes_sent: # hack b/c self.send has unhandled exceptions
    break
### end insert
data = data[bytes_sent:]

Would be interested to hear any problems using the above

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.