Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.6.6, JRuby 1.6.7
-
Fix Version/s: JRuby 1.7.0.pre1
-
Component/s: None
-
Labels:None
-
Number of attachments :
Description
I'm working on some socket code that uses IO.select() and Socket#connect_nonblock to do connects with timeout, pretty much in the same way as the Ruby MRI docs have example code(1) for such:
I have sample code that works fine in MRI 1.9.x And 1.8.x, but not JRuby 1.6.7 (in either 1.8 or 1.9 modes)
Sample code: https://github.com/jordansissel/experiments/blob/master/ruby/sockets/connect-nonblock.rb
Here is the output running under many different rubies:
{:version=>"1.9.2 @ jruby-1.6.5", :socket=>nil}
{:version=>"1.9.2 @ ruby", :socket=>#<Socket:fd 3>}
{:version=>"1.9.2 @ jruby-1.6.6", :socket=>nil}
{:version=>"1.9.3 @ ruby", :socket=>#<Socket:fd 5>}
{:version=>"1.9.2 @ jruby-1.6.7", :socket=>nil}
The problem appears to be the behavior of IO.select. In my sample code, I expect the 'writer' to be an array containing the socket - when the socket is connected. JRuby seems to not do this:
reader, writer, error = IO.select(nil, [socket], nil, timeout)
p :version => PLATFORM, :writer => writer
output:
{:version=>"1.8.7 @ jruby-1.6.5", :writer=>nil}
{:version=>"1.9.2 @ ruby", :writer=>[#<Socket:fd 3>]}
{:version=>"1.8.7 @ jruby-1.6.6", :writer=>nil}
{:version=>"1.9.3 @ ruby", :writer=>[#<Socket:fd 5>]}
{:version=>"1.8.7 @ jruby-1.6.7", :writer=>nil}
(1) See 'example code' from MRI docs http://ruby-doc.org/stdlib-1.9.3/libdoc/socket/rdoc/Socket.html#method-i-connect_nonblock
I have been randomly able to get IO.select to behave, but I haven't figured out a sample case yet. Of course, I could be hallucinating, been hacking at this for a while