Project

General

Profile

Actions

Bug #11134

closed

resolution of "localhost" in windows server 2012 (ipv6 over ipv4)

Added by Anonymous almost 9 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:69124]

Description

I've just installed ruby 2.2 on Windows Server 2012 and i'm seeing this strange behaviour:

The server:

require "socket"

server = TCPServer.new("::1", 2000)
loop do
  client = server.accept
  client.puts "Hello !"
  client.close
end

in this case, a tcp connection to that server (using "localhost") goes fine, e.g.

TCPSocket.new("localhost", 2000).close # => processed instantly

BUT if the server bind on 127.0.0.1 or 0.0.0.0 (instead of ::1) the previous request takes at least 1 second to be processed.

The same occurs in windows server 2008, but there it can be fixed inserting the line "127.0.0.1 localhost" into the hosts file while in windows server 2012 the delay persists.

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Closed

I don't think this is a bug. TCPServer.new binds to the first address that matches for the hostname. In your example, you are explicitly binding to the IPv6 address and not the IPv4 address, so if the DNS resolution in your environment tries IPv4 first, there will be a timeout before it tries IPv6.

If you want to avoid the delay, bind to both IPv4 and IPv6 using Socket.tcp_server_sockets:

servers = Socket.tcp_server_sockets("localhost", 2000)
Actions

Also available in: Atom PDF

Like0
Like0