diff --git a/spec/support/test_server_manager.rb b/spec/support/test_server_manager.rb index e519480a..672cefa4 100644 --- a/spec/support/test_server_manager.rb +++ b/spec/support/test_server_manager.rb @@ -160,7 +160,7 @@ def external_servers_running? end def port_open?(port, host = "127.0.0.1") - Socket.tcp(host, port, connect_timeout: 1).close + TCPSocket.new(host, port, connect_timeout: 1).close true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH false @@ -202,10 +202,14 @@ def stop_server_type(server_type) end end + # TCPSocket.new is used instead of Socket.tcp because Socket.tcp(connect_timeout:) + # on Ruby <= 4.0.6 returns a socket for a refused connection on Darwin (the retry + # connect(2) answers EISCONN, ruby-core Bug #22223), which made this readiness + # check a no-op and let the first spec race the fixture server boot. def wait_for_port(port, host = "127.0.0.1", timeout = 15) with_timeout(timeout) do loop do - Socket.tcp(host, port, connect_timeout: 1).close + TCPSocket.new(host, port, connect_timeout: 1).close break rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH sleep 0.1