Issue #11134 has been updated by jeremyevans0 (Jeremy Evans).

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`:

```ruby
servers = Socket.tcp_server_sockets("localhost", 2000)
```

----------------------------------------
Bug #11134: resolution of "localhost" in windows server 2012 (ipv6 over ipv4)
https://bugs.ruby-lang.org/issues/11134#change-80659

* Author: Anonymous
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
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.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>