classification
Title: PySSL_SSLread loops until data is available, even in non-blocking mode
Type: Stage:
Components: Library (Lib) Versions: Python 3.3, Python 3.2, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: exarkun, pitrou
Priority: normal Keywords:

Created on 2010-09-16 22:22 by exarkun, last changed 2010-09-16 22:46 by exarkun. This issue is now closed.

Messages (3)
msg116629 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2010-09-16 22:22
Here's a transcript which demonstrates the blocking behavior:

>>> import socket
>>> import time
>>> import ssl
>>> s = ssl.wrap_socket(socket.socket())
>>> s.connect(('localhost', 8443))
>>> s.send('GET /async.rpy HTTP/1.1\r\n\r\n')
27
>>> s.setblocking(False)
>>> a = time.time(); s.recv(1024); b = time.time()
'HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\nDate: Thu, 02 Sep 2010 11:51:03 GMT\r\nContent-Type: text/html\r\nServer: TwistedWeb/10.1.0+r29954\r\n\r\n4c\r\n<html><body>Sorry to keep you waiting.</body></html>\r\n0\r\n\r\n'
>>> print b - a
4.13403391838
>>>

(This can be reproduced using any web server which is a bit slow in responding; it's very obvious here because I used a server that intentionally waits several seconds before generating a response).
msg116630 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-16 22:32
It was corrected between 2.6.5 and 2.6.6 (see r79291 and also potentially r80453).

Here, on the 2.6 maintenance branch:

>>> import socket, time, ssl
>>> s = ssl.wrap_socket(socket.socket())
>>> s.connect(('linuxfr.org', 443))
>>> s.setblocking(False)
>>> s.recv(1024)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/antoine/cpython/27/Lib/ssl.py", line 219, in recv
    return self.read(buflen)
  File "/home/antoine/cpython/27/Lib/ssl.py", line 138, in read
    return self._sslobj.read(len)
ssl.SSLError: [Errno 2] _ssl.c:1348: The operation did not complete (read)

Can you check with 2.6.6 or the release26-maint SVN head?
msg116631 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2010-09-16 22:46
Hm.  I must have been testing with old versions, since I can't reproduce this now.  Sorry for the noise.
History
Date User Action Args
2010-09-16 22:46:24exarkunsetstatus: pending -> closed
resolution: out of date -> duplicate
messages: + msg116631
2010-09-16 22:32:29pitrousetstatus: open -> pending

nosy: + pitrou
messages: + msg116630

resolution: out of date
2010-09-16 22:25:56exarkunsettitle: PySSL_SSLRead loops until data is available, even in non-blocking mode -> PySSL_SSLread loops until data is available, even in non-blocking mode
2010-09-16 22:22:57exarkuncreate