cryptography icon indicating copy to clipboard operation
cryptography copied to clipboard

osrandom engine already registered

Open komakino opened this issue 11 years ago • 23 comments

Getting "osrandom engine already registered" from cryptography module when including requests in kodi addon.

http://xbmclogs.com/pq07deaup

I'm on Ubuntu 14.04 LTS based system with python 2.7.6.

komakino avatar Aug 21 '15 08:08 komakino

Hey @komakino, this usually happens when using threading. Can you confirm that the "kodi addon" is using threading? Also can you link to that project since I have no clue what project it is.

sigmavirus24 avatar Aug 21 '15 12:08 sigmavirus24

Also, can you include the version of "kodi" that you're using, the version of requests that's installed, and the version of cryptography in use?

sigmavirus24 avatar Aug 21 '15 12:08 sigmavirus24

I remain baffled as to how this condition can occur under the threading lock we have. :cry:

reaperhulk avatar Aug 21 '15 16:08 reaperhulk

Kodi: 15.1 Git:d496682 requests: 2.6.0

komakino avatar Aug 21 '15 21:08 komakino

thats my addon, that I'm developing. I do not use threading. I also tested in a "clean" addon, just importing requests and got the same results.

komakino avatar Aug 21 '15 21:08 komakino

Oh, and cryptography is 1.0

komakino avatar Aug 21 '15 21:08 komakino

@komakino does that plugin get imported by something using threading? What is kodi a plugin for?

sigmavirus24 avatar Aug 21 '15 23:08 sigmavirus24

I'm seeing the same thing in a Django app running under mod_wsgi which is triggered as soon as something imports requests (I noticed it with raven-python but even a simple import requests fails in the threaded WSGIDaemon environment):

[Tue Sep 08 12:07:05.808805 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533] Traceback (most recent call last):
[Tue Sep 08 12:07:05.808838 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/example/example_wsgi.py", line 7, in <module>
[Tue Sep 08 12:07:05.808924 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     import requests
[Tue Sep 08 12:07:05.808941 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/wdl/.virtualenv/lib/python2.7/site-packages/requests/__init__.py", line 53, in <module>
[Tue Sep 08 12:07:05.809377 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     from .packages.urllib3.contrib import pyopenssl
[Tue Sep 08 12:07:05.809401 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/wdl/.virtualenv/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 53, in <module>
[Tue Sep 08 12:07:05.810151 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     import OpenSSL.SSL
[Tue Sep 08 12:07:05.810174 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/wdl/.virtualenv/lib/python2.7/site-packages/OpenSSL/__init__.py", line 8, in <module>
[Tue Sep 08 12:07:05.810240 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     from OpenSSL import rand, crypto, SSL
[Tue Sep 08 12:07:05.810256 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/wdl/.virtualenv/lib/python2.7/site-packages/OpenSSL/rand.py", line 11, in <module>
[Tue Sep 08 12:07:05.810374 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     from OpenSSL._util import (
[Tue Sep 08 12:07:05.810397 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/wdl/.virtualenv/lib/python2.7/site-packages/OpenSSL/_util.py", line 7, in <module>
[Tue Sep 08 12:07:05.810498 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     binding = Binding()
[Tue Sep 08 12:07:05.810515 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/wdl/.virtualenv/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 63, in __init__
[Tue Sep 08 12:07:05.810614 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     self._ensure_ffi_initialized()
[Tue Sep 08 12:07:05.810638 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/wdl/.virtualenv/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 95, in _ensure_ffi_initialized
[Tue Sep 08 12:07:05.810665 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     cls._register_osrandom_engine()
[Tue Sep 08 12:07:05.810680 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]   File "/opt/wdl/.virtualenv/lib/python2.7/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 70, in _register_osrandom_engine
[Tue Sep 08 12:07:05.810705 2015] [:error] [pid 25018:tid 140561562785536] [remote 127.0.0.1:42533]     raise RuntimeError("osrandom engine already registered")

acdha avatar Sep 08 '15 12:09 acdha

@acdha that's roughly the same environment I'm seeing this in. Can you share your simple app? It may help with reproduction/debugging. I'd like to try with this PR to see if I can still reproduce this.

sigmavirus24 avatar Sep 08 '15 12:09 sigmavirus24

Let me see how simple I can make it – my app isn't simple but I could reproduce simply by tossing import requests at the top of the WSGI file.

acdha avatar Sep 08 '15 13:09 acdha

Yeah, even this will trigger it with the import requests line uncommented:

#!/usr/bin/env python
# encoding: utf-8

# import requests

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

Relevant Apache config:

WSGIDaemonProcess example user=example-site group=www-data processes=8 threads=8 maximum-requests=20000 shutdown-timeout=120 deadlock-timeout=60 display-name=example home=/opt/example python-path=/opt/example/.virtualenv/lib/python2.7/site-packages
WSGIImportScript /opt/example/example_wsgi.py application-group=example process-group=example

WSGILazyInitialization On
WSGIRestrictEmbedded On

acdha avatar Sep 08 '15 13:09 acdha

This is related to the subinterpreters used by mod_wsgi. We're tracking this in #2299.

reaperhulk avatar Sep 12 '15 17:09 reaperhulk

One of our Emby users is experiencing this issue (log is attached in the post): http://emby.media/community/index.php?/topic/25735-emby-for-kodi-broken-no-sync/

Is there anything we can do on our side to prevent this error from happening? So far, it seems to affect only one user.

Emby add-on for Kodi: https://github.com/MediaBrowser/Emby.Kodi Requests is imported here: https://github.com/MediaBrowser/Emby.Kodi/blob/master/resources/lib/DownloadUtils.py

angelblue05 avatar Sep 24 '15 02:09 angelblue05

The issue might come from Kodi and not Emby, I experienced similar errors (osrandom engine already registered) in Kodi with addons requesting connection to websites (trakt.tv). Note that I'm a noob user, not a developper.

All the info are in the same emby.media thread : http://emby.media/community/index.php?/topic/25735-emby-for-kodi-broken-no-sync/

jeromebruzaud avatar Sep 24 '15 05:09 jeromebruzaud

For the record: https://github.com/pyca/cryptography/pull/2293 fixed this problem for me (see also https://github.com/pyca/cryptography/issues/2299#issuecomment-144066145 )

toabctl avatar Sep 29 '15 13:09 toabctl

This is merged!

alex avatar Oct 25 '15 02:10 alex

Hi,

Is there actually a fix for this in Kodi? On Ubuntu 15.10 the python libs are sufficiently different that the fix on 2293 doesn't apply cleanly (plus I'd be updating system .py files).

micahg avatar Nov 10 '15 16:11 micahg

@micahg try installing cryptography 1.1 from pip, which contains this change. To do this you may need to uninstall python-cryptography from apt though.

reaperhulk avatar Nov 10 '15 16:11 reaperhulk

@reaperhulk that worked, tyvm.

micahg avatar Nov 11 '15 00:11 micahg

This nonsense happened to me today in Kodi running on Linux. It killed the YouTube plugin dead so it wouldn't even start up.

I had to resort to deleting python cryptography and python openssl on the underlying Linux system that hosts my Kodi box using the package manager. Kodi 17.0 OpenSUSE LEAP 42.1

You'd think after the number of years this issue has existed someone would have fixed it.

TheRealTachyon avatar Mar 19 '17 23:03 TheRealTachyon