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
Activity
| Field | Original Value | New Value |
|---|---|---|
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Assignee | Thomas E Enebo [ enebo ] | Charles Oliver Nutter [ headius ] |
| Fix Version/s | JRuby 1.7 [ 17049 ] | |
| Resolution | Fixed [ 1 ] |
| Comment |
[ To make it easier for others to find ServerSocket in the future, I've added an #accept impl to Socket that just errors and points users to ServerSocket at http://wiki.jruby.org/ServerSocket.
{noformat} commit 7fb8ea02a5292b6a64de218253b756e1c14c61fb Author: Charles Oliver Nutter <headius@headius.com> Date: Tue Mar 6 23:44:50 2012 -0600 Add error message for Socket#accept. Because we can't support both client and server connections in Socket, we have added ServerSocket for the server side. To make this easier to find, I've added an impl of Socket#accept that mentions ServerSocket and links to an informational page on the JRuby wiki. {noformat} ] |