Skip to content

Instantly share code, notes, and snippets.

@junosuarez
Created August 10, 2016 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junosuarez/ecc845b10adf68faf26ff3c9edd3f1ba to your computer and use it in GitHub Desktop.
Save junosuarez/ecc845b10adf68faf26ff3c9edd3f1ba to your computer and use it in GitHub Desktop.
If you suddenly get a lot of cryptic errors in travis like `Errno::EINVAL: Errno::EINVAL: Invalid argument - bind(2) for "fe80::4001:aff:::fff" port 9515` then maybe this will save you 5 hours
# Monkeypatch Selenium Webdriver to work on Travis IPv6 infrastructure
module Selenium
module WebDriver
class PortProber
IGNORED_ERRORS = [Errno::EADDRNOTAVAIL, Errno::EINVAL, Errno::EACCES].freeze
IGNORED_ERRORS << Errno::EBADF if Platform.cygwin?
def self.free?(port)
interfaces = Socket.getaddrinfo('localhost', 8080).map { |e| e[3] }
interfaces.each do |host|
begin
TCPServer.new(host, port).close
rescue *IGNORED_ERRORS => ex
$stderr.puts "port prober could not bind to #{host}:#{port} (#{ex.message})" if $DEBUG
# ignored - some machines appear unable to bind to some of their interfaces
end
end
true
rescue
false
end
end # PortProber
end # WebDriver
end # Selenium
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment