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

Commit 369b515

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

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/celluloid/io/dns_resolver.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def initialize
2929

3030
# The non-blocking secret sauce is here, as this is actually a
3131
# Celluloid::IO::UDPSocket
32-
@socket = UDPSocket.new(@server.family)
32+
unless @socket = UDPSocket.new(@server.family)
33+
fail SocketError, "nodename nor servname provided, or not known"
34+
end
3335
end
3436

3537
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(SocketError)
46+
end
4247
end
4348
end

0 commit comments

Comments
 (0)