begin
@socket.connect_nonblock Socket.sockaddr_in(remote_port, @addr.to_s)
rescue Errno::EINPROGRESS, Errno::EALREADY
wait_writable
# HAX: for some reason we need to finish_connect ourselves on JRuby
# This logic is unnecessary but JRuby still throws Errno::EINPROGRESS
# if we retry the non-blocking connect instead of just finishing it
retry unless defined?(JRUBY_VERSION) && @socket.to_channel.finish_connect
rescue Errno::EISCONN
# We're now connected! Yay exceptions for flow control
# NOTE: This is the approach the Ruby stdlib docs suggest ;_;
end
https://github.com/celluloid/celluloid/issues/436#issuecomment-91058400
Proposed fix: