select(sock) indicates not-ready, but sock.recv does not block
Nikolaus Rath
Nikolaus at rath.org
Mon Feb 17 20:29:42 EST 2014
Nikolaus Rath <Nikolaus at rath.org> writes:
> Hello,
>
> I have a problem with using select. I can reliably reproduce a situation
> where select.select((sock.fileno(),), (), (), 0) returns ((),(),())
> (i.e., no data ready for reading), but an immediately following
> sock.recv() returns data without blocking.
[...]
Turns out that I fell into the well-known (except to me) ssl-socket
trap: http://docs.python.org/3/library/ssl.html#notes-on-non-blocking-sockets
TL;DR: Relying on select() on an SSL socket is not a good idea because
some internal buffering is done. Better put the socket in non-blocking
mode and try to read something, catching the ssl.Want* exception if
nothing is ready.
Best,
-Nikolaus
--
Encrypted emails preferred.
PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C
»Time flies like an arrow, fruit flies like a Banana.«
More information about the Python-list
mailing list