select(sock) indicates not-ready, but sock.recv does not block

N

Nikolaus Rath

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.

I am pretty sure that this is not a race condition. The behavor is 100%
reproducible, the program is single threaded, and even waiting for 10
seconds before the select() call does not change the result.

I'm running Python 3.3.3 under Linux 3.12.

Has anyone an idea what might be going wrong here?

Thanks,
-Nikolaus
 
R

Roy Smith

Nikolaus Rath said:
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.

I am pretty sure that this is not a race condition. The behavor is 100%
reproducible, the program is single threaded, and even waiting for 10
seconds before the select() call does not change the result.

I'm running Python 3.3.3 under Linux 3.12.

Has anyone an idea what might be going wrong here?

Thanks,
-Nikolaus

Can you post the code which demonstrates this?

Also, with any kind of networking problem, tcpdump is your fried. When
you run your code, use tcpdump to watch all the network traffic on
whatever port your socket is bound to. That might give you some clues
what's going on.

Likewise, I would also strace the process and watch all the network
system calls. The problem you're describing might be unexpected
behavior in Python, or it might be in the kernel. Watching the actual
system calls that are generated will narrow it down to which.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top