From: Eric Wong Date: 2011-08-03T11:20:33+09:00 Subject: [ruby-core:38733] Re: [Ruby 1.9 - Bug #5138][Open] Add nonblocking IO that does not use exceptions for EOF and EWOULDBLOCK Tanaka Akira wrote: > 2011/8/2 Eric Wong : > > > 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