Skip to content

A platform for community discussion. Free, open, simple.

DEV: Try another workaround for `getaddrinfo: Temporary failure in name resolution` (#27410)

Alan Guo Xiang Tance91767b90bc
diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb
index cfe6234d191..c7ad52d781b 100644
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -522,26 +522,20 @@ RSpec.configure do |config|
# This is a monkey patch for the `Capybara.using_session` method in `capybara`. For some
# unknown reasons on Github Actions, we are seeing system tests failing intermittently with the error
# `Socket::ResolutionError: getaddrinfo: Temporary failure in name resolution` when the app tries to resolve
- # `localhost` from within a `Capybara#using_session` block. Therefore, we will ensure we can resolve `localhost` first
- # before starting the new session.
+ # `localhost` from within a `Capybara#using_session` block.
#
# Too much time has been spent trying to debug this issue and the root cause is still unknown so we are just dropping
- # this workaround for now.
+ # this workaround for now where we will retry the block once before raising the error.
+ #
+ # Potentially related: https://bugs.ruby-lang.org/issues/20172
module Capybara
class << self
def using_session_with_localhost_resolution(name, &block)
- self._using_session(name) do |session|
- attempts = 0
-
- begin
- Socket.getaddrinfo("localhost", 80, Socket::AF_INET, Socket::SOCK_STREAM)
- rescue Socket::ResolutionError
- attempts += 1
- attempts <= 3 ? retry : raise
- end
-
- block.call(session)
- end
+ attempts = 0
+ self._using_session(name, &block)
+ rescue Socket::ResolutionError
+ puts "Socket::ResolutionError error encountered... Current thread count: #{Thread.list.size}"
+ attempts <= 1 ? retry : raise
end
end
end