[Python-Dev] the new 2.3a1 settimeout() with httplib and SSL
Guido van Rossum
guido@python.org
Fri, 24 Jan 2003 19:58:15 -0500
> I'm trying to get the new socket.settimeout() in Python 2.3a1 to work in
> conjunction with httplib and SSL. This code seems to work fine:
>
> import httplib
> conn = httplib.HTTPConnection('ncsdevtest.nameconnector.com', 80)
> conn.connect()
> conn.sock.settimeout(90)
> conn.request('GET', '/cgi-bin/Pause30.cgi')
> response = conn.getresponse()
> print response.status, response.reason
> data = response.read()
> print 'read', len(data), 'bytes'
> conn.close()
>
> Where Pause30.cgi is a cgi script that simply sleeps for 30 seconds then
> sends back a simple response.
>
> As-is, this program returns after 30 seconds. If I adjust the timeout of 90
> to be, lets say, 5 seconds, I correctly get a timeout exception after 5
> seconds. So far, so good.
>
> But if I change HTTPConnection to HTTPSConnection and change 80 to 443, I
> have trouble -- my CPU usage goes up to 100%, the python process sucks up
> more and more memory, and it doesn't time out at all. It does still returns
> the correct response after 30 seconds.
>
> Is there a way to do this? Should I enter a bug report?
Hm, when I added the timeout feature, I didn't think of SSL at all. I
imagine that SSL gets an error and keeps retrying immediately, rather
than using select() to block until more data is available.
Part of this is that this simply doesn't work for SSL -- you shouldn't
do that. (Sorry if you want it -- it's beyond my capabilities to hack
this into the SSL code.)
Part of this is that the SSL code should refuse a socket that's in
nonblocking mode, *or* perhaps should restore blocking mode; I'm not
sure.
Anyway, please do enter a bug report. (A patch would be even cooler!)
--Guido van Rossum (home page: http://www.python.org/~guido/)