[Python-Dev] the new 2.3a1 settimeout() with httplib and SSL
Geoffrey Talvola
gtalvola@nameconnector.com
Mon, 27 Jan 2003 14:47:57 -0500
Guido van Rossum [mailto:guido@python.org] wrote:
> > 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!)
It doesn't look terribly hard to make the SSL wrapper obey the timeout, by
calling select() on the "raw" socket before calling SSL_write or SSL_read.
I'm willing to try to get this to work.
I'm not able to get this far though, because when I try to build _ssl I have
problems. When I run build_ssl.py it grinds away for several minutes
building OpenSSL, then fails with this message while building openssl.exe:
link /nologo /subsystem:console /machine:I386 /opt:ref
/out:out32\openssl.exe @C:\temp\nnb00239.
NMAKE : fatal error U1073: don't know how to make
'D:\Python-2.3a1-Source\openssl-0.9.7/out32.dbg/libeay32.lib'
The weird thing is that that file already exists.
Can anyone help me out here? This is Windows NT with VC++ 6.0. I've
successfully built OpenSSL before, but there's something about the way it's
being built by build_ssl.py that's failing.
- Geoff