Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: JRuby 1.5.3
-
Fix Version/s: JRuby 1.6.7
-
Component/s: None
-
Labels:None
-
Environment:repros under os x 10.6.4 with 1.6.0_22 and centos 5.4 with 1.6.0_21
-
Number of attachments :
Description
After doing a connect_nonblock then it appears that IO.select will always return immediately and indicate the socket is not writable, when it should instead block and eventually return that it is writable, assuming the connection succeeds.
Example below. Note that this does not appear to be a timing specific issue; the sleep 5 gives it plenty of time to connect, and the select does not wait for the timeout before returning. Presumably calling connect_nonblock again updates some state that was out of sync.
>> @timeout=5
=> 5
>> @host='google.com'
=> "google.com"
>> @port=80
=> 80
>> addrinfo = ::Socket::getaddrinfo(@host, @port).first
=> ["AF_INET", 80, "pz-in-f99.1e100.net", "74.125.127.99", 2, 2, 17]
>> @handle = ::Socket.new(addrinfo[4], ::Socket::SOCK_STREAM, 0)
=> #<Socket:0x417470d0>
>> sockaddr = ::Socket.sockaddr_in(addrinfo[1], addrinfo[3])
=> "\020\002\000PJ}\177c\000\000\000\000\000\000\000\000"
>> @handle.connect_nonblock(sockaddr)
Errno::EINPROGRESS: Operation now in progress - Operation now in progress
from (irb):18:in `connect_nonblock'
from (irb):18
>> sleep(5)
=> 5
>> t=Time.now; IO.select(nil, [ @handle ], nil, @timeout); puts Time.now-t
0.001
=> nil
>> @handle.connect_nonblock(sockaddr)
Errno::EISCONN: Socket is already connected - Socket is already connected
from (irb):21:in `connect_nonblock'
from (irb):21
>> IO.select(nil, [ @handle ], nil, @timeout)
=> [[], [#<Socket:0x417470d0>], []]
Issue Links
- is related to
-
JRUBY-6449
connect_nonblock + select needs to eventually finishConnect
-
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.6.7 [ 18315 ] | |
| Resolution | Fixed [ 1 ] |
| Link |
This issue is related to |
| Status | Resolved [ 5 ] | Closed [ 6 ] |
I'm not sure what the correct behavior is here. When I run the following simplified example under both Ruby and JRuby, the results are pretty much identical:
~/projects/jruby ➔ ruby -rsocket -e "addr = Socket.getaddrinfo('google.com', 80).first; sock = Socket.new(addr[4], Socket::SOCK_STREAM, 0); sockaddr = Socket.sockaddr_in(addr[1], addr[3]); begin; sock.connect_nonblock(sockaddr); rescue Errno::EINPROGRESS => e; p e; end; t = Time.now; IO.select(nil, [sock], nil, 5); puts Time.now - t; sock.connect_nonblock(sockaddr)" #<Errno::EINPROGRESS: Operation now in progress - connect(2)> 0.000818 -e:1:in `connect_nonblock': Socket is already connected - connect(2) (Errno::EISCONN) from -e:1 ~/projects/jruby ➔ jruby -rsocket -e "addr = Socket.getaddrinfo('google.com', 80).first; sock = Socket.new(addr[4], Socket::SOCK_STREAM, 0); sockaddr = Socket.sockaddr_in(addr[1], addr[3]); begin; sock.connect_nonblock(sockaddr); rescue Errno::EINPROGRESS => e; p e; end; t = Time.now; IO.select(nil, [sock], nil, 5); puts Time.now - t; sock.connect_nonblock(sockaddr)" #<Errno::EINPROGRESS: Operation now in progress - Operation now in progress> 0.016 -e:1:in `connect_nonblock': Socket is already connected - Socket is already connected (Errno::EISCONN) from -e:1