Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: e69fc1a61199
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8fddbafc9b3b
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Aug 10, 2016

  1. Fix Socket.tcp connect_timeout option

    Before commit `Socket.tcp(host, port, connect_timeout: 0.1)`
    ignored timeout option. This happened because `connect_internal`
    mistakenly responded with `:wait_readable` instead of `:wait_writable`.
    After fixing it this code started to constantly fail with timeout error.
    Checking for OP_CONNECT in IO#wait_writable fixed this issue.
    etehtsea committed Aug 10, 2016
    Copy the full SHA
    dcf4571 View commit details

Commits on Aug 11, 2016

  1. Merge pull request #4061 from etehtsea/fix-connect-timeout

    Fix Socket.tcp connect_timeout option
    enebo authored Aug 11, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8fddbaf View commit details
Showing with 23 additions and 3 deletions.
  1. +2 −1 core/src/main/java/org/jruby/ext/io/wait/IOWaitLibrary.java
  2. +1 −1 core/src/main/java/org/jruby/ext/socket/RubySocket.java
  3. +20 −1 test/jruby/test_socket.rb
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ext/io/wait/IOWaitLibrary.java
Original file line number Diff line number Diff line change
@@ -155,7 +155,8 @@ public static IRubyObject wait_writable(ThreadContext context, IRubyObject _io,
if (tv < 0) throw runtime.newArgumentError("time interval must be positive");
}

boolean ready = fptr.ready(runtime, context.getThread(), SelectionKey.OP_WRITE, tv);
boolean ready = fptr.ready(runtime, context.getThread(), SelectionKey.OP_CONNECT | SelectionKey.OP_WRITE, tv);

fptr.checkClosed();
if (ready)
return io;
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ext/socket/RubySocket.java
Original file line number Diff line number Diff line change
@@ -530,7 +530,7 @@ else if (channel instanceof DatagramChannel) {
}

if ( ! result ) {
if (!ex) return runtime.newSymbol("wait_readable");
if (!ex) return runtime.newSymbol("wait_writable");
throw runtime.newErrnoEINPROGRESSWritableError();
}
}
21 changes: 20 additions & 1 deletion test/jruby/test_socket.rb
Original file line number Diff line number Diff line change
@@ -245,6 +245,26 @@ def test_tcp_socket_errors
end
end

def test_connect_nonblock_no_exception
serv = ServerSocket.new(:INET, :STREAM)
serv.bind(Socket.sockaddr_in(0, "127.0.0.1"), 5)
c = Socket.new(:INET, :STREAM)
servaddr = serv.getsockname
rv = c.connect_nonblock(servaddr, exception: false)
case rv
when 0
# some OSes return immediately on non-blocking local connect()
else
assert_equal :wait_writable, rv
end
assert_equal([ [], [c], [] ], IO.select(nil, [c], nil, 60))
assert_equal(0, c.connect_nonblock(servaddr, exception: false),
'there should be no EISCONN error')
ensure
serv.close if serv
c.close if c
end

end


@@ -667,4 +687,3 @@ def test_read_zero_never_blocks
client.close rescue nil
end if RUBY_VERSION >= '1.9'
end