Created
September 7, 2011 22:46
-
-
Save rcrowley/1202033 to your computer and use it in GitHub Desktop.
What happens when using Eventlet and inheriting an SSL socket file descriptor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import eventlet | |
import eventlet.debug | |
import optparse | |
import socket | |
import ssl | |
eventlet.monkey_patch(os=True, | |
select=True, | |
socket=True, | |
thread=True, | |
time=True) | |
eventlet.debug.hub_prevent_multiple_readers(False) | |
fd = 0 # It's not actually zero but it's an integer and it really is a socket. | |
c = socket.SocketType(_sock=socket.fromfd(fd, | |
socket.AF_INET, | |
socket.SOCK_STREAM)) | |
if options.cert and options.key: | |
c = eventlet.wrap_ssl(c, | |
certfile=options.cert, | |
keyfile=options.key, | |
server_side=True, | |
ssl_version=ssl.PROTOCOL_SSLv23) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Traceback from running the code above: | |
Traceback (most recent call last): | |
File "keepalived.py", line 209, in <module> | |
ssl_version=ssl.PROTOCOL_SSLv23) | |
File "/usr/local/lib/python2.6/dist-packages/eventlet/convenience.py", line 116, in wrap_ssl | |
return wrap_ssl_impl(sock, *a, **kw) | |
File "/usr/local/lib/python2.6/dist-packages/eventlet/green/ssl.py", line 285, in wrap_socket | |
return GreenSSLSocket(sock, *a, **kw) | |
File "/usr/local/lib/python2.6/dist-packages/eventlet/green/ssl.py", line 46, in __init__ | |
super(GreenSSLSocket, self).__init__(sock.fd, *args, **kw) | |
File "/usr/lib/python2.6/ssl.py", line 113, in __init__ | |
cert_reqs, ssl_version, ca_certs) | |
TypeError: sslwrap() argument 1 must be _socket.socket, not GreenSocket | |
# Traceback if the socket.SocketType call is removed, thus initializing c to a _socket.socket object: | |
Traceback (most recent call last): | |
File "keepalived.py", line 212, in <module> | |
ssl_version=ssl.PROTOCOL_SSLv23) | |
File "/usr/local/lib/python2.6/dist-packages/eventlet/convenience.py", line 116, in wrap_ssl | |
return wrap_ssl_impl(sock, *a, **kw) | |
File "/usr/local/lib/python2.6/dist-packages/eventlet/green/ssl.py", line 285, in wrap_socket | |
return GreenSSLSocket(sock, *a, **kw) | |
File "/usr/local/lib/python2.6/dist-packages/eventlet/green/ssl.py", line 46, in __init__ | |
super(GreenSSLSocket, self).__init__(sock.fd, *args, **kw) | |
File "/usr/lib/python2.6/ssl.py", line 92, in __init__ | |
socket.__init__(self, _sock=sock._sock) | |
AttributeError: '_socket.socket' object has no attribute '_sock' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment