From: Bill Kelly Date: 2010-04-26T13:46:54+09:00 Subject: Re: Networking: select() blocks for seconds (> timeout) Raul Parolari wrote: > I am using Ruby (as a prototype version) to communicate with a network > of solar cells (driven by firmware), over Udp. It works most of the time > perfectly (delivering messages with 1-5 milliseconds precision, even > beyond what we need). > > But once in a while, this happens (ubuntu machine) while waiting the > response (from solar cells): > > result = select(( [ comm ], nil, [ comm ], 0.050)) > > if result.nil? > # handle 50 msec timeout > else > # data > end > > All is perfect for several thousands of messages, until this: we receive > data (in the "else" branch) 5 seconds later; so, the select remained > blocked for 5 seconds without signaling the 50 msec timeout. Hi, Here was an original discussion of the issue: (something like, select may have already succeeded, before a bad UDP checksum is detected by the kernel) http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/148443 Here is a kludge-workaround I ended up using: (via timeout) http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/304785 These days, I use EventMachine. Hope this helps, Bill