celluloid / celluloid-io

UNMAINTAINED: See celluloid/celluloid#779 - Evented sockets for Celluloid actors
https://celluloid.io
MIT License
879 stars 93 forks source link

[DNSResolver] Raise SocketError when there’s no connection. #171

Open alloy opened 8 years ago

alloy commented 8 years ago

In short, what I tried to fix is the following behaviour when trying to resolve a hostname when offline:

irb(main):001:0> require 'celluloid/current'
=> true
irb(main):002:0> require 'celluloid/io'
=> true
irb(main):003:0> Celluloid::IO::TCPSocket.new("www.google.com", 80)
NoMethodError: undefined method `"\u0000\u0002\u0001\u0000\u0000\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0003www\u0006google\u0003com\u0000\u0000\u0001\u0000\u0001"' for nil:NilClass
    from /Users/eloy/.gem/ruby/2.3.0/gems/celluloid-io-0.17.3/lib/celluloid/io/dns_resolver.rb:44:in `resolve'
    from /Users/eloy/.gem/ruby/2.3.0/gems/celluloid-io-0.17.3/lib/celluloid/io/tcp_socket.rb:101:in `create_socket'
    from /Users/eloy/.gem/ruby/2.3.0/gems/celluloid-io-0.17.3/lib/celluloid/io/tcp_socket.rb:53:in `initialize'
    from /Users/eloy/.gem/ruby/2.3.0/gems/celluloid-io-0.17.3/lib/celluloid/io/socket.rb:39:in `new'
    from /Users/eloy/.gem/ruby/2.3.0/gems/celluloid-io-0.17.3/lib/celluloid/io/socket.rb:39:in `new'
    from (irb):3
    from /Users/eloy/.rubies/ruby-2.3.0/bin/irb:11:in `<main>'

What happens is that @socket remains nil here which means that you end up sending the hostname as a NilClass#send message here.


With stdlib it raises the following exception, although that one is actually not raised by the name resolver, but by Socket:

irb(main):001:0> require 'socket'
=> false
irb(main):002:0> TCPSocket.new("www.google.com", 80)
SocketError: getaddrinfo: nodename nor servname provided, or not known
    from (irb):2:in `initialize'
    from (irb):2:in `new'
    from (irb):2
    from /Users/eloy/.rubies/ruby-2.3.0/bin/irb:11:in `<main>'

The one raised by Resolv is:

irb(main):001:0> Resolv.getaddress("www.google.com")
Resolv::ResolvError: no address for www.google.com
    from /Users/eloy/.rubies/ruby-2.3.0/lib/ruby/2.3.0/resolv.rb:95:in `getaddress'
    from /Users/eloy/.rubies/ruby-2.3.0/lib/ruby/2.3.0/resolv.rb:45:in `getaddress'
    from (irb):1
    from /Users/eloy/.rubies/ruby-2.3.0/bin/irb:11:in `<main>'

I’m not sure which one I should use, any thoughts?

ioquatix commented 8 years ago

probably the one from socket?

ioquatix commented 8 years ago

perhaps a new exception would make sense... SocketNameResolutionError < SocketError?

alloy commented 8 years ago

Sure, I can do that, and keep the same error message, yeah?

alloy commented 8 years ago

@ioquatix Like so?

ioquatix commented 8 years ago

Yeah that seems fine.

ioquatix commented 8 years ago

@tarcieri still waiting for travis issues to be fixed, boop :)

tarcieri commented 8 years ago

@ioquatix that was on nio4r. The test failures look like the same on master (we never got celluloid-io back to green)

ioquatix commented 8 years ago

ah okay I guess I'll take a look at the issues here.