{"record":{"id":"61d34e2cd375215f","repo":"SeleniumHQ/selenium","slug":"unable-to-translate-localhost-for-tcp-ipv4","errorCode":null,"errorMessage":"unable to translate 'localhost' for TCP + IPv4","messagePattern":"unable to translate 'localhost' for TCP \\+ IPv4","errorType":"exception","errorClass":"Error::WebDriverError","httpStatus":null,"severity":"error","filePath":"rb/lib/selenium/webdriver/common/platform.rb","lineNumber":158,"sourceCode":"        assert_file(path)\n\n        return if File.executable? path\n\n        raise Error::WebDriverError, \"not executable: #{path.inspect}\"\n      end\n\n      def exit_hook\n        pid = Process.pid\n\n        at_exit { yield if Process.pid == pid }\n      end\n\n      def localhost\n        info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM\n\n        return info[0][3] unless info.empty?\n\n        raise Error::WebDriverError, \"unable to translate 'localhost' for TCP + IPv4\"\n      end\n\n      def ip\n        orig = Socket.do_not_reverse_lookup\n        Socket.do_not_reverse_lookup = true\n\n        begin\n          UDPSocket.open do |s|\n            s.connect '8.8.8.8', 53\n            return s.addr.last\n          end\n        ensure\n          Socket.do_not_reverse_lookup = orig\n        end\n      rescue Errno::ENETUNREACH, Errno::EHOSTUNREACH\n        # no external ip\n      end\n","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/rb/lib/selenium/webdriver/common/platform.rb#L140-L176","documentation":"Platform.localhost resolves the string 'localhost' to an IPv4 address via Socket.getaddrinfo. If the call returns an empty list (no address info), it raises WebDriverError. This indicates the local system cannot resolve 'localhost' over TCP/IPv4.","triggerScenarios":"Running in a container or sandbox whose /etc/hosts lacks a localhost entry. A broken or minimal DNS/hosts configuration. Network namespace where localhost resolution is unavailable.","commonSituations":"Docker/container images with a stripped /etc/hosts. Sandboxed CI runners with restricted networking. Systems where IPv4 loopback is disabled.","solutions":["Ensure /etc/hosts contains a '127.0.0.1 localhost' entry.","In containers, use an image that includes a proper hosts file or configure it at startup.","Verify with Socket.getaddrinfo('localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM) on the host."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"info = Socket.getaddrinfo('localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM)\nraise 'localhost unresolvable; check /etc/hosts' if info.empty?","typeGuard":null,"tryCatchPattern":"begin\n  Selenium::WebDriver::Platform.localhost\nrescue Selenium::WebDriver::Error::WebDriverError => e\n  raise unless e.message.include?('localhost')\n  '127.0.0.1'\nend","preventionTips":["Ensure /etc/hosts has a '127.0.0.1 localhost' entry, especially in containers.","Validate localhost resolution during container/CI image setup.","Avoid disabling IPv4 loopback on the host."],"tags":["ruby","platform","network","dns","localhost"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}