Skip to content

Commit

Permalink
Waiting till Socket connection completed (#6909)
Browse files Browse the repository at this point in the history
After `select` we should use `getsockopt` to read the SO_ERROR option at
level SOL_SOCKET to determine that connection completed successfully

http://man7.org/linux/man-pages/man2/connect.2.html
  • Loading branch information
N0xFF authored and twalpole committed Mar 7, 2019
1 parent a5f241f commit e8bd56e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rb/lib/selenium/webdriver/common/socket_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def listening?
begin
sock.connect_nonblock sockaddr
rescue Errno::EINPROGRESS
retry if IO.select(nil, [sock], nil, CONNECT_TIMEOUT)
retry if socket_writable?(sock) && conn_completed?(sock)
raise Errno::ECONNREFUSED
rescue *CONNECTED_ERRORS
# yay!
Expand All @@ -85,6 +85,14 @@ def listening?
false
end

def socket_writable?(sock)
IO.select(nil, [sock], nil, CONNECT_TIMEOUT)
end

def conn_completed?(sock)
sock.getsockopt(Socket::SOL_SOCKET, Socket::SO_ERROR).int.zero?
end

def with_timeout
max_time = time_now + @timeout

Expand Down

0 comments on commit e8bd56e

Please sign in to comment.