-
-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error: [Errno 0] Error #1618
Comments
// offtopic comment
I'd recommend adding your user to |
@Safihre thanks for your report and reproducible example. I'm not an expert in SSL and haven't had time to sort out related issues. I know that some issues with SSL exist and here's another one: cherrypy/cheroot#6. Also, since SSL has moved to Any ideas? |
@webknjaz Sure I can try with just from cheroot import wsgi
def my_crazy_app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
return ['Hello world!']
addr = '0.0.0.0', 8070
server = wsgi.Server(addr, my_crazy_app)
server.start() |
probably: import cheroot.server
ssl_module = 'builtin'
ssl_adapter_cls = cheroot.server.get_ssl_adapter_class(ssl_module)
server.ssl_adapter = ssl_adapter_cls(...corresponding args here) |
I suspect it might be related to https://stackoverflow.com/a/38224367, which looks reasonable since you run frozen python app IIRC. |
It looks like https://github.com/openssl/openssl/blob/1f5878b/ssl/ssl_lib.c#L3450-L3481 returns 0 and wrapper in cpython raises that as an error not adding additional insight. |
In the reported cases it's not run frozen, but as a regular python 2 application. |
that's weird. I'd suspect it's maybe because of privileges. Have you tried that under |
PyOpenSSL uses
|
Have no tried sudo since we use a port that should normally not require it. |
Some dudes think that errno 0 shouldn't be raised as an exception https://bugs.python.org/msg299759 |
Also, this might be related to OpenSSL version https://bugs.python.org/issue28689 |
Yes it seems specific to this 1.1.0 version. |
Some of the complaints on the Internet seem to mention client connections, which close socket without fully completing the handshake. |
apache/thrift#1321 suggest additionally catching |
So, during comparison with your example snippet I noticed that we also have fcntl modifications on Also you don't load a CA file (FTR) |
So I've done some debugging and it seems that during startup some of components tries to do a connection to server. |
(connection comes from the same process) |
I've used this snippet and confirmed that the issue is not happening in pure Cheroot: #! /usr/bin/env python
from cheroot import server, wsgi
addr = '0.0.0.0', 8070
ssl_module = 'builtin'
ssl_adapter_cls = server.get_ssl_adapter_class(ssl_module)
ssl_adapter_kwargs = {'certificate': '/root/.sabnzbd/admin/server.cert', 'private_key': '/root/.sabnzbd/admin/server.key'}
def my_crazy_app(environ, start_response):
status = '200 OK'
response_headers = [('Content-type','text/plain')]
start_response(status, response_headers)
return ['Hello world!']
server = wsgi.Server(addr, my_crazy_app)
server.ssl_adapter = ssl_adapter_cls(**ssl_adapter_kwargs)
server.start() |
@Safihre I've checked it down to |
Thanks :) |
This issue arose in my latest xubuntu 18.04 installation containing python3.6.5, cherrypy-15.0.0 and cheroot-6.3.1. Following the leads in this issue's comments led to a bit more detail and (for my installation) a workaround: Remove the test for python2. ...Not ready to write a pull request, there are several testing dependencies as yet unresolved. :-) In case the diff is useful, feel free to use it, I impose no license restrictions on its use. |
@len-samuelson I'm inlining your patch since it's a better experience not to have to download files to just see text: diff --git a/cheroot/ssl/builtin.py b/cheroot/ssl/builtin.py
index cc3866b1..2c472bc1 100644
--- a/cheroot/ssl/builtin.py
+++ b/cheroot/ssl/builtin.py
@@ -130,15 +130,22 @@ class BuiltinSSLAdapter(Adapter):
except generic_socket_error as exc:
"""It is unclear why exactly this happens.
- It's reproducible only under Python 2 with openssl>1.0 and stdlib
- ``ssl`` wrapper, and only with CherryPy.
- So it looks like some healthcheck tries to connect to this socket
- during startup (from the same process).
+ It's reproducible under both Python 2 and Python3.6 with openssl>1.0
+ and stdlib ``ssl`` wrapper. CherryPy uses portend.py to verify that
+ the server port is ready for incoming connections (code ref
+ cherrypy/process/servers.py:260). Portend tries to connect to a
+ port then close it without performing any action (such as starting
+ an SSL handshake). That causes what OPENSSL probably thinks is a
+ protocol violation, raising OSError with error 0. This exception
+ handler is extended to work with Python3 by removing the test for
+ python2, and assumes the OSError args (likely raised by python's
+ openssl code) are (0, 'Error').
Ref: https://github.com/cherrypy/cherrypy/issues/1618
"""
- if six.PY2 and exc.args == (0, 'Error'):
+ EMPTY_RESULT = None, {}
+ if exc.args == (0, 'Error'):
return EMPTY_RESULT
raise
return s, self.get_environ(s) |
@Safihre that issue is about setting up some minimum TLS testing at all. It's not specific to the current one. |
@msinn probably because everyone forgot about it :) Feel free to send a PR! |
@Safihre |
Python 3.7 only supports OpenSSL 1.1+ and its built-in ssl module wrapper handles this error correctly. Older Pythons, however, don't do this raising an obscure error with code 0 and no sane explanation. So combo of Python<3.7 and OpenSSL>=1.1 raises this exception if HTTP client connects to HTTPS-configured socket. We're addressing this issue by swallowing the exception under conditions described above. Ref cherrypy/cherrypy#1618
Python 3.7 only supports OpenSSL 1.1+ and its built-in ssl module wrapper handles this error correctly. Older Pythons, however, don't do this raising an obscure error with code 0 and no sane explanation. So combo of Python<3.7 and OpenSSL>=1.1 raises this exception if HTTP client connects to HTTPS-configured socket. We're addressing this issue by swallowing the exception under conditions described above. Ref cherrypy/cherrypy#1618 Co-Authored-By: Len Samuelson <[email protected]>
Hey @len-samuelson @Safihre @msinn, So I've pushed a bit more granular version of that patch. It looks like Python 3.7's ssl module handles this because it only supports 1.1, but older versions supported 1.0 and probably didn't fully cover errors of 1.1. |
Am I not understanding the cause of this issue correctly or should this be an It is my understanding that if you're running Python <3.7 but OpenSSL 1.1 then you will get the weird 0 error code. So if you have 3.7 (which requires OpenSSL 1.1+ anyway) then you should be good. But if you had Python 3.6 for example we'd want to suppress the error by returning So I would think the conditional would either be this: if is_error0 and IS_BELOW_PY37:
return EMPTY_RESULT or perhaps this to be more explicit if is_error0 and (IS_BELOW_PY37 or IS_BELOW_OPENSSL11):
return EMPTY_RESULT but I don't the current syntax (with |
Oh, sorry. It looks like I messed up :) P.S. Kind reminder: it is always better to send a PR rather than post things in the closed issue where comments may be left unnoticed for various reasons. |
Should be fine now. I've changed |
Perfect, thanks a lot! |
Hey folks, Im still seeing this issue with Python 3.7.1, openssl 1.1.0g, CherryPy 18.1.0 and cheroot 6.5.4 [14/Jan/2019:21:30:03] ENGINE Error in HTTPServer.tick
Traceback (most recent call last):
File "/home/sylvain/.venv/lib/python3.7/site-packages/cheroot/server.py", line 1753, in serve
self.tick()
File "/home/sylvain/.venv/lib/python3.7/site-packages/cheroot/server.py", line 1958, in tick
s, ssl_env = self.ssl_adapter.wrap(s)
File "/home/sylvain/.venv/lib/python3.7/site-packages/cheroot/ssl/builtin.py", line 117, in wrap
sock, do_handshake_on_connect=True, server_side=True,
File "/usr/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/usr/lib/python3.7/ssl.py", line 853, in _create
self.do_handshake()
File "/usr/lib/python3.7/ssl.py", line 1117, in do_handshake
self._sslobj.do_handshake()
OSError: [Errno 0] Error Is that expected?
|
@Lawouach it's probably a bug. You should file an issue under Cheroot I guess and let's try to come up with a reproducer because it doesn't fail in CI. How did you check openssl version btw? What about earlier versions? I've done a massive TLS refactoring (and still doing it), can it be a regression? |
And what about 3.7.2? |
I haven't had the chance to update on my local machine. For the openssl version:
Today, I was actually setting a simple local CA using mkcert as per http://woile.github.io/posts/local-https-development-in-python-with-mkcert/ |
@Lawouach is that for testing? I've migrated Cheroot to |
Here's how you identify which version stdlib ssl module is linked against: $ python -c 'import ssl; print("\nOPENSSL_VERSION: " + ssl.OPENSSL_VERSION + "\nOPENSSL_VERSION_INFO: " + repr(ssl.OPENSSL_VERSION_INFO) + "\nOPENSSL_VERSION_NUMBER: " + repr(ssl.OPENSSL_VERSION_NUMBER))' |
Here is the output: $ python -c 'import ssl; print("\nOPENSSL_VERSION: " + ssl.OPENSSL_VERSION + "\nOPENSSL_VERSION_INFO: " + repr(ssl.OPENSSL_VERSION_INFO) + "\nOPENSSL_VERSION_NUMBER: " + repr(ssl.OPENSSL_VERSION_NUMBER))'
OPENSSL_VERSION: OpenSSL 1.1.0g 2 Nov 2017
OPENSSL_VERSION_INFO: (1, 1, 0, 7, 15)
OPENSSL_VERSION_NUMBER: 269484159 Thank you a lot for trustme. I wasn't aware of it and it is indeed for testing. |
Could you please verify that Cheroot tests pass on your machine? It looks like depending on env combo some bits of |
All tests in cheroot master do pass fine indeed. |
So maybe it's a misconfiguration in |
P.S. Here's a collection of TLS related testing tools I've found earlier while researching TLS: cherrypy/cheroot#95 |
@Lawouach oh and does it happen when you start CherryPy app but before you try sending any requests? It might be the checker thing which effectively punches port over HTTP to see that it's alive. |
@webknjaz This error is still there, also on Python 3.7 using default Python Windows installer. https://bugs.python.org/issue31122 I did a
|
Anyone reading this, the fix for now is:
Before
|
@webknjaz the patch for this in Python has been merged, finally: https://bugs.python.org/issue31122 |
On Debian 9, with OpenSSL
1.1.0f 25 May 2017
CherryPy will thrown this (non-fatal) error on startup when using the'server.ssl_module': 'builtin'
. It does not happen when using'server.ssl_module': 'pyopenssl'
.This is not just on our older CherryPy, but also on the latest CherryPy version 11 and both on Python 2.7 and Python 3.5.
We have been chasing this error for a while and first assumed it was a bug in Python. I was ready to report it to Python bug-tracker, but I cannot reproduce it using pure-python. So it really is something specific to what CherryPy does.
Code:
Error thrown by Python 2.7 and 3.5:
Pure-python code version trying to reproduce all steps cherrypy performs, that does not thrown the error:
@sanderjo also created a guide to setting-up a docker to with Debian to test this:
sabnzbd/sabnzbd#1000
For non-docker-people like me, this command can be used to copy files into the docker:
The text was updated successfully, but these errors were encountered: