Project

General

Profile

Actions

Bug #3787

closed

TCPSocket.new() fails on IPv6 connections for IPV4/IPv6 hosts

Added by adamm (Adam Majer) over 13 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
Backport:
[ruby-core:32055]

Description

=begin
$ host localhost
localhost has address 127.0.0.1
localhost has IPv6 address ::1


server setup is just listening to ::1 address,

require 'socket'
s = TCPServer.new( '::1', 1200 )
s.accept


then I try to connect to this with client socket,

irb(main):001:0> require 'socket'
=> true
irb(main):002:0> TCPSocket.new( 'localhost', 1200 )
Errno::ECONNREFUSED: Connection refused - connect(2)
from (irb):2:in initialize' from (irb):2:in new'
from (irb):2
from :0
irb(main):003:0> TCPSocket.new( '::1', 1200 )
=> #TCPSocket:0x7f54d1c0aeb8

Clearly, the 'localhost' should try to iterate through the addresses until it can connect, not fail. Python works correctly. telnet as well,

$ telnet localhost 1200
Trying ::1...
Connected to localhost.
=end

Actions #1

Updated by shyouhei (Shyouhei Urabe) over 13 years ago

  • Status changed from Open to Feedback

=begin
Cannot reproduce on my machine (Ubuntu lucid x86_64, no iptables entry, SELinux disabled).

  • ruby 1.9.1p430 (2010-08-16 revision 28997) [x86_64-linux]
  • ruby 1.9.2p0 (2010-08-18 revision 29034) [x86_64-linux]
  • ruby 1.9.3dev (2010-09-14 trunk 29247) [x86_64-linux]

all can connect to a server listening at ::1:1200.

% netstat -lnt
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 ::1:1200 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN

=end

Actions #2

Updated by matsuda (Akira Matsuda) over 13 years ago

=begin
I just got the same error on my machine (Mac OSX 10.6) with both Ruby 1.8.7 and 1.9.2.

% ruby -d -v -rsocket -e "TCPSocket.new '::1', 1200"
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
Exception Errno::ECONNREFUSED' at -e:1 - Connection refused - connect(2) -e:1:in initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from -e:1:in `new'
from -e:1

% ruby -d -v -rsocket -e "TCPSocket.new '::1', 1200"
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-darwin10.4.0]
Exception Errno::ECONNREFUSED' at -e:1 - Connection refused - connect(2) -e:1:in initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from -e:1:in new' from -e:1:in '

=end

Actions #3

Updated by shyouhei (Shyouhei Urabe) over 13 years ago

=begin
@a_matsuda: Isn't that a different situation? The original issue is that the reporter cannot connect to 'localhost', while he seems to be possible to connect to '::1'.
=end

Actions #4

Updated by matsuda (Akira Matsuda) over 13 years ago

=begin
Oh, sorry. You're right.

In my case, while I can connect to 1200 via v4,

% ruby -d -v -rsocket -e "p TCPSocket.new('127.0.0.1', 1200)"
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
#TCPSocket:0x10018a078

it fails to connect using v6.

% ruby -d -rsocket -e "p TCPSocket.new('::1', 1200)"
Exception Errno::ECONNREFUSED' at -e:1 - Connection refused - connect(2) -e:1:in initialize': Connection refused - connect(2) (Errno::ECONNREFUSED)
from -e:1:in `new'
from -e:1

And I'm sure '::1' stands for localhost.

% ruby -d -rsocket -e "p IPSocket.getaddress('localhost')"
"::1"

Should I post another ticket for this?
=end

Actions #5

Updated by nahi (Hiroshi Nakamura) almost 13 years ago

  • Project changed from Ruby 1.8 to Ruby master
  • Category changed from core to core

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Feedback to Closed

I close this as Rejected since no feedback provided.
Please reopen this if it still happens on the latest version of ruby.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0