Skip to content

Commit

Permalink
pyopenssl: wait for data before handshake retry
Browse files Browse the repository at this point in the history
Affects requests made to SSL servers running in the same thread via green
threads.

http://stackoverflow.com/questions/19109436/gevent-ssl-wsgiserver-blocks-when-it-shouldnt
  • Loading branch information
t-8ch committed Oct 1, 2013
1 parent 5062ac6 commit a49bec5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions urllib3/contrib/pyopenssl.py
Expand Up @@ -26,6 +26,7 @@
from pyasn1.codec.der import decoder as der_decoder
from socket import _fileobject
import ssl
import select
from cStringIO import StringIO

from .. import connectionpool
Expand Down Expand Up @@ -336,6 +337,7 @@ def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
try:
cnx.do_handshake()
except OpenSSL.SSL.WantReadError:
select.select([sock], [], [])
continue
except OpenSSL.SSL.Error as e:
raise ssl.SSLError('bad handshake', e)
Expand Down

4 comments on commit a49bec5

@SaveTheRbtz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select.select() does not work if sock's underlying fd >= 1024[0], would you mind switching to select.poll[1] here? Or maybe using poll when it's available and falling back to select and catching ValueError exception?

[0] ValueError: filedescriptor out of range in select()
[1] It's been part of SuSv2/POSIX.1-2001 for quite a while, so it should be safe to assume that it's supported by most UNIXes and Windows Vista+: http://pubs.opengroup.org/onlinepubs/007908799/xsh/poll.html

@shazow
Copy link
Member

@shazow shazow commented on a49bec5 Apr 11, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we're going to have to do something like this: https://github.com/shazow/urllib3/blob/master/urllib3/util/connection.py#L12

@shazow
Copy link
Member

@shazow shazow commented on a49bec5 Apr 11, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SaveTheRbtz Could you open an issue please with these details?

@SaveTheRbtz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done: #589

Please sign in to comment.