Skip to content
This repository was archived by the owner on Dec 7, 2018. It is now read-only.

Commit af08ced

Browse files
committed
[DNSResolver] Raise SocketError when there’s no connection.
1 parent cf249b9 commit af08ced

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/celluloid/io/dns_resolver.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Celluloid
55
module IO
66
# Asynchronous DNS resolver using Celluloid::IO::UDPSocket
77
class DNSResolver
8+
class SocketNameResolutionError < SocketError; end
9+
810
# Maximum UDP packet we'll accept
911
MAX_PACKET_SIZE = 512
1012
DNS_PORT = 53
@@ -29,7 +31,9 @@ def initialize
2931

3032
# The non-blocking secret sauce is here, as this is actually a
3133
# Celluloid::IO::UDPSocket
32-
@socket = UDPSocket.new(@server.family)
34+
unless @socket = UDPSocket.new(@server.family)
35+
fail SocketNameResolutionError, "nodename nor servname provided, or not known"
36+
end
3337
end
3438

3539
def resolve(hostname)

spec/celluloid/io/dns_resolver_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,10 @@
3939
expect(results).to be_an_instance_of(Resolv::IPv4)
4040
end
4141
end
42+
43+
it "raises SocketError if unable to connect to the nameserver" do
44+
allow(Celluloid::IO::UDPSocket).to receive(:new).and_return(nil)
45+
expect { Celluloid::IO::DNSResolver.new }.to raise_error(Celluloid::IO::DNSResolver::SocketNameResolutionError)
46+
end
4247
end
4348
end

0 commit comments

Comments
 (0)