New submission from Dave Tian:

Hi there,

Recent urlopen with timeout did not work. Below is the back trace. After 
digging into the Python lib, the root cause is found - within the socket.py, 
self._sock.recv(), under a 'while True' loop, tried to retrieve sth from the 
under-layer SSL socket. However, the under-layer PySSL_SSLread() neither 
returned anything useful nor reported an exception, such as timeout. Because of 
this 'while True' loop, urlopen got stuck. My temp fix is to add timeout within 
this issued loop of the socket.py. However, there are other similar loops 
ranging from urllib2, httplib to socket...and I do not think anything wrong 
with these loops considering the system socket programming practice. Instead, I 
am thinking if we could add a new timeout value into the socket object. This 
new timeout starts with the same value as the user-defined timeout but decrease 
for the same socket operation. For the case I have encountered:

while True:
    some_sock_recv() # decrease the timeout value within the function call

This should guarantee the timeout timely even within the 'while True' loop.


Thanks,
Dave

http://davejingtian.org




>>> obj=urllib2.urlopen(url, timeout=20)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 127, in urlopen
    return _opener.open(url, data, timeout)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 410, in open
    response = meth(req, response)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 523, in http_response
    'http', request, response, code, msg, hdrs)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 442, in error
    result = self._call_chain(*args)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 382, in _call_chain
    result = func(*args)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 629, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 404, in open
    response = self._open(req, data)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 422, in _open
    '_open', req)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 382, in _call_chain
    result = func(*args)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 1222, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py",
 line 1187, in do_open
    r = h.getresponse(buffering=True)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
 line 1045, in getresponse
    response.begin()
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
 line 441, in begin
    self.msg = HTTPMessage(self.fp, 0)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/mimetools.py",
 line 25, in __init__
    rfc822.Message.__init__(self, fp, seekable)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/rfc822.py",
 line 108, in __init__
    self.readheaders()
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py",
 line 280, in readheaders
    line = self.fp.readline(_MAXLINE + 1)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py",
 line 476, in readline
    data = self._sock.recv(self._rbufsize)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
 line 241, in recv
    return self.read(buflen)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py",
 line 160, in read
    return self._sslobj.read(len)
KeyboardInterrupt
>>>

----------
components: Library (Lib)
messages: 231160
nosy: daveti
priority: normal
severity: normal
status: open
title: urlopen timeout failed with SSL socket
type: behavior
versions: Python 2.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22870>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to