Tanaka Akira <akr / fsij.org> wrote:
> 2011/8/2 Eric Wong <normalperson / yhbt.net>:
> 
> > That use of select + readpartial is unsafe.  Spurious wakeup is a
> > documented behavior of the select() system call, data can be received
> > but checksums can be incorrect and data is discarded (after process is
> > woken up from select()).
> 
> If you mean about Linux, it is already fixed (or have workaround) 6 years ago.
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/151776
> 
> I don't know other example of spurious wakeup.

Maybe not exactly "spurious wakeup", but the data can be already be read
by another thread/process by the time the reader tries to read.
While uncommon for stream sockets since they lack defined atomicity
rules, it's common for UDP or other message-oriented socket protocols
(and even Unix pipes).

accept() + multiple processes sharing a listener is a common example
of this.

Yehuda's patch doesn't include non-raising variants of accept_nonblock
and connect_nonblock, but kgio also includes kgio_tryaccept and
Kgio::Socket.start(addr)[1] that do not raise on EAGAIN/EINPROGRESS.


[1] kgio refuses to do DNS lookup, addr should be pre-packed

-- 
Eric Wong