Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

1.1.0 - cannot connect with hostname #55

Closed
brackxm opened this issue Oct 31, 2013 · 9 comments
Closed

1.1.0 - cannot connect with hostname #55

brackxm opened this issue Oct 31, 2013 · 9 comments

Comments

@brackxm
Copy link
Contributor

brackxm commented Oct 31, 2013

require 'cql'
client = Cql::Client.connect(host: 'localhost')
client.close

works with 1.0.6, does not work with 1.1.0

error:
synchronous_client.rb:32:in `connect': Connection refused - connect(2) (Cql::Io::ConnectionError)

might be related to issue #50
however this is without other dependencies

same error with the use_resolv branch

connecting on ip address works

using ruby 1.9.3-p448

@iconara
Copy link
Owner

iconara commented Oct 31, 2013

What operating system? I've noticed that I have problems on OS X with localhost since it doesn't resolve to 127.0.0.1 but only IPv6-addresses, and C* doesn't listen to those it seems.

@iconara
Copy link
Owner

iconara commented Oct 31, 2013

But weird it if works in 1.0.6. I'll have to see what's different between those versions.

@brackxm
Copy link
Contributor Author

brackxm commented Oct 31, 2013

yes, OS X

@iconara
Copy link
Owner

iconara commented Nov 4, 2013

The only difference between v1.0 and v1.1 is that the latter doesn't specify IPv4 when looking up the IP for the hostname you give it (apart from a few other features that don't have to do with name resolution):

# v1.0
# specifying AF_INET here
addrinfo = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
_, port, _, ip, address_family, socket_type = addrinfo.first
@sockaddr = Socket.sockaddr_in(port, ip)
@io = Socket.new(address_family, socket_type, 0)
@io.connect_nonblock(@sockaddr)

# v1.1
unless @addrinfos
  @connection_started_at = @clock.now
  # not specifying AF_INET here
  @addrinfos = @socket_impl.getaddrinfo(@host, @port, nil, Socket::SOCK_STREAM)
end
unless @io
  _, port, _, ip, address_family, socket_type = @addrinfos.shift
  @sockaddr = @socket_impl.sockaddr_in(port, ip)
  @io = @socket_impl.new(address_family, socket_type, 0)
end
unless connected?
  @io.connect_nonblock(@sockaddr)
  @connected = true
  @connected_promise.fulfill(self)
end

could you run this in IRB and give me the output? (my output is inline):

require 'socket'
Socket.getaddrinfo('localhost', 9042, Socket::AF_INET, Socket::SOCK_STREAM)
# => [["AF_INET", 9042, "127.0.0.1", "127.0.0.1", 2, 1, 6]]
Socket.getaddrinfo('localhost', 9042, nil, Socket::SOCK_STREAM)
# => [["AF_INET", 9042, "127.0.0.1", "127.0.0.1", 2, 1, 6], ["AF_INET6", 9042, "::1", "::1", 30, 1, 6], ["AF_INET6", 9042, "fe80::1%lo0", "fe80::1%lo0", 30, 1, 6]]

What the v1.1 also does is that it tries all of the addresses returned, while v1.0 specified IPv4 and tried only the first address. However, it does not retry on a Errno::ECONNREFUSED. I tried reversing the order of the IPv4 and IPv6 entries in my list to simulate what would happen if they for some reason came in that order, and that fails. Maybe that's what's happening for you?

I've pushed up a branch called retry_connection_on_refused, try that and see if it works for you.

@brackxm
Copy link
Contributor Author

brackxm commented Nov 4, 2013

> Socket.getaddrinfo('localhost', 9042, Socket::AF_INET, Socket::SOCK_STREAM)
=> [["AF_INET", 9042, "127.0.0.1", "127.0.0.1", 2, 1, 6]]
> Socket.getaddrinfo('localhost', 9042, nil, Socket::SOCK_STREAM)
=> [["AF_INET6", 9042, "::1", "::1", 30, 1, 6], ["AF_INET", 9042, "127.0.0.1", "127.0.0.1", 2, 1, 6], ["AF_INET6", 9042, "fe80::1%lo0", "fe80::1%lo0", 30, 1, 6]]

yes, it seems my order is different and ipv6 is first

@brackxm
Copy link
Contributor Author

brackxm commented Nov 4, 2013

Yes, the code on that branch works for me.

@mhakeem
Copy link

mhakeem commented Nov 6, 2013

I am using Mac OSX Mavericks, ruby 2 (2.0.0p247 (2013-06-27 revision 41674) [x86_64-darwin12.3.0]), Cassandra 1.2.10 with CQL 3. I was able to connect the first time, but I couldn't connect after that. I got the following error in irb and I get the same error when I run my ruby file (the following was implemented in irb):

2.0.0p247 :002 > require 'cql'
 => true 
2.0.0p247 :003 > client = Cql::Client.connect(host: 'localhost')
Cql::Io::ConnectionError: Connection refused - connect(2)
    from /Users/m/.rvm/gems/ruby-2.0.0-p247@cassandra/gems/cql-rb-1.1.0/lib/cql/client/synchronous_client.rb:32:in `connect'
    from /Users/m/.rvm/gems/ruby-2.0.0-p247@cassandra/gems/cql-rb-1.1.0/lib/cql/client.rb:99:in `connect'
    from (irb):3
    from /Users/m/.rvm/rubies/ruby-2.0.0-p247/bin/irb:13:in `<main>'

I tried the exact same code on Ubuntu 12.04 and 13.10 with Cassandra 1.2.10 and 2.0.2 and it worked fine on all of them.

@iconara
Copy link
Owner

iconara commented Nov 6, 2013

@mhakeem thanks for reporting this too. I will push out a fix shortly.

@iconara iconara closed this as completed in 155d7a4 Nov 7, 2013
@iconara
Copy link
Owner

iconara commented Nov 7, 2013

v1.1.1 has been released with this fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants