Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66628
| From | Nikolaus Rath <Nikolaus@rath.org> |
|---|---|
| Subject | Re: select(sock) indicates not-ready, but sock.recv does not block |
| References | <87a9dq9rh1.fsf@vostro.rath.org> |
| Date | 2014-02-17 17:29 -0800 |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7112.1392686986.18130.python-list@python.org> (permalink) |
Nikolaus Rath <Nikolaus@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.«
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: select(sock) indicates not-ready, but sock.recv does not block Nikolaus Rath <Nikolaus@rath.org> - 2014-02-17 17:29 -0800
csiph-web