Skip to content

Commit

Permalink
Revert "Remove JRuby-specifiy SocketPoller#listening?"
Browse files Browse the repository at this point in the history
This reverts commit eaa1047.
In JRuby 3.0.0 there seems to be regression which causes the same bug.
See jruby/jruby#5709 (comment)
for details.
  • Loading branch information
p0deje committed Oct 11, 2021
1 parent c9a2ef6 commit d456395
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions rb/lib/selenium/webdriver/common/socket_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,37 @@ def closed?
arr << Errno::EALREADY if Platform.wsl?
}.freeze

def listening?
addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])

begin
sock.connect_nonblock sockaddr
rescue Errno::EINPROGRESS
retry if socket_writable?(sock) && conn_completed?(sock)
raise Errno::ECONNREFUSED
rescue *CONNECTED_ERRORS
# yay!
if Platform.jruby?
# we use a plain TCPSocket here since JRuby has issues closing socket
# see https://github.com/jruby/jruby/issues/5709
def listening?
TCPSocket.new(@host, @port).close
true
rescue *NOT_CONNECTED_ERRORS
false
end
else
def listening?
addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])

begin
sock.connect_nonblock sockaddr
rescue Errno::EINPROGRESS
retry if socket_writable?(sock) && conn_completed?(sock)
raise Errno::ECONNREFUSED
rescue *CONNECTED_ERRORS
# yay!
end

sock.close
true
rescue *NOT_CONNECTED_ERRORS
sock&.close
WebDriver.logger.debug("polling for socket on #{[@host, @port].inspect}")
false
end

sock.close
true
rescue *NOT_CONNECTED_ERRORS
sock&.close
WebDriver.logger.debug("polling for socket on #{[@host, @port].inspect}")
false
end

def socket_writable?(sock)
Expand Down

0 comments on commit d456395

Please sign in to comment.