rubydns
rubydns copied to clipboard
rubydns unexpected quit on windows
the issue happned on both windows7 and win10, to reproduce the issue: 1. start rubydns 2.run nslookup in the same computer, then the issue happened. I checked the log and found that endpoint can't bind to socket again if socket error happened. I checked the code and I don't know how to fix it.
I use ruby2.6-64, here is my server code: #!/usr/bin/env ruby require 'rubydns'
INTERFACES = [ [:udp, "192.168.95.47", 53], ]
IN = Resolv::DNS::Resource::IN
UPSTREAM = RubyDNS::Resolver.new([[:tcp, "8.8.8.8", 53]])
RubyDNS::run_server(INTERFACES) do match(%r{test.local}, IN::A) do |transaction| transaction.respond!("10.0.0.80") end
otherwise do |transaction|
transaction.passthrough!(UPSTREAM)
end
end
here is the log(on win10-x64):
E:>ruby -d basic-dns.rb
Exception LoadError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/rubygems.rb:1397 - cannot load such file -- rubygems/defaults/ruby Exception
LoadError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59 - cannot load such file -- rubydns
C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubydns-2.0.2/lib/rubydns.rb:31: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-io-1.17.2/lib/async/io/socket.rb:124: warning: shadowing outer local variable - task
C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-io-1.17.2/lib/async/io/socket.rb:216: warning: shadowing outer local variable - task
Exception SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().autoclose= ^ Exception
SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().pos= ^ Exception
SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().do_not_reverse_lookup= ^ Exception
NameError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/fiddle/import.rb:157 - uninitialized constant Fiddle::Function::STDCALL
C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-dns-1.2.0/lib/async/dns/extensions/resolv.rb:29: warning: parentheses after method name is interpreted as an argument list, not a decomposed argument
C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-dns-1.2.0/lib/async/dns/extensions/resolv.rb:53: warning: method redefined; discarding old to_s
C:/plong/Ruby25-x64/lib/ruby/2.5.0/resolv.rb:1304: warning: previous definition of to_s was here
C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-dns-1.2.0/lib/async/dns/extensions/resolv.rb:57: warning: method redefined; discarding old inspect
C:/plong/Ruby25-x64/lib/ruby/2.5.0/resolv.rb:1236: warning: previous definition of inspect was here
Exception SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().hostname= ^ Exception
SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().sync_close= ^ Exception
SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - SyntaxError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/forwardable/impl.rb:6 - <compiled>: syntax error, unexpected end-of-input ().reactor= ^ C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-dns-1.2.0/lib/async/dns/resolver.rb:217: warning: assigned but unused variable - peer C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-dns-1.2.0/lib/async/dns/handler.rb:124: warning: assigned but unused variable - error C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-dns-1.2.0/lib/async/dns/transport.rb:80: warning: assigned but unused variable - count 0.2s: Starting Async::DNS server (v1.2.0)... 0.2s: Async::IO::Socket : Binding to #<Addrinfo: 192.168.95.47:53 UDP> 0.21s: <> Listening for datagrams on #<Addrinfo: 192.168.95.47:53 UDP> 4.82s: <> Receiving incoming query (44 bytes) to Async::DNS::DatagramHandler... : <1> Processing question 47.95.168.192.in-addr.arpa Resolv::DNS::Resource::IN::PTR... : <1> Searching for 47.95.168.192.in-addr.arpa Resolv::DNS::Resource::IN::PTR : <1> Checking rule [/test.local/, Resolv::DNS::Resource::IN::A]... 4.82s: <1> Resource class Resolv::DNS::Resource::IN::PTR failed to match Resolv::DNS::Resource::IN::A! 4.82s: [60973] Sending request [[#<Resolv::DNS::Name: 47.95.168.192.in-addr.arpa.>, Resolv::DNS::Resource::IN::PTR]] to address #<Async::IO::HostEndpoint:0x00000000057369f0 @options={}, @specification=["8.8.8.8", 53, nil, 1]> 4.82s: [60973] -> Try address #<Async::IO::HostEndpoint name="8.8.8.8" service=53 family=nil type=1 protocol=nil flags=nil> 4.82s: Async::IO::Socket : Connecting to #<Addrinfo: 8.8.8.8:53 TCP> 6.82s: <> Receiving incoming query (28 bytes) to Async::DNS::DatagramHandler... : <2> Processing question google.com Resolv::DNS::Resource::IN::A... : <2> Searching for google.com Resolv::DNS::Resource::IN::A : <2> Checking rule [/test.local/, Resolv::DNS::Resource::IN::A]... 6.83s: <2> No pattern matched. 6.83s: [3933] Sending request [[#<Resolv::DNS::Name: google.com.>, Resolv::DNS::Resource::IN::A]] to address #<Async::IO::HostEndpoint:0x000000000573ef38 @options={}, @specification=["8.8.8.8", 53, nil, 1]> 6.83s: [3933] -> Try address #<Async::IO::HostEndpoint name="8.8.8.8" service=53 family=nil type=1 protocol=nil flags=nil> 6.83s: Async::IO::Socket : Connecting to #<Addrinfo: 8.8.8.8:53 TCP> 7.17s: [60973] <- Try address #<Async::IO::HostEndpoint name="8.8.8.8" service=53 family=nil type=1 protocol=nil flags=nil> = #<Resolv::DNS::Message:0x000000000573d0c0> 7.17s: [60973] Received valid response with 0 answer(s). : <1> Time to process request: 2.353993s 7.17s: <1> Writing 44 bytes response to client via UDP... Exception
Errno::ECONNRESET' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/socket.rb:444 - An existing connection was forcibly closed by the remote host. - recvmsg(2)
7.17s: <Async::Task:0x2b62acc binding to #<Addrinfo: 192.168.95.47:53 UDP> failed>
| Errno::ECONNRESET: An existing connection was forcibly closed by the remote host. - recvmsg(2)
| → C:/plong/Ruby25-x64/lib/ruby/2.5.0/socket.rb 444
| C:/plong/Ruby25-x64/lib/ruby/2.5.0/socket.rb 444
| C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-io-1.17.2/lib/async/io/generic.rb 128
| C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-io-1.17.2/lib/async/io/generic.rb 47
| C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-dns-1.2.0/lib/async/dns/handler.rb 72
| C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-dns-1.2.0/lib/async/dns/server.rb 116
| C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-io-1.17.2/lib/async/io/socket.rb 220
| C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-1.13.0/lib/async/task.rb 198
Exception Async::TimeoutError' at C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-1.13.0/lib/async/task.rb:51 - execution expired Exception
Async::TimeoutError' at C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-io-1.17.2/lib/async/io/socket.rb:180 - execution expired
Exception Async::TimeoutError' at C:/plong/Ruby25-x64/lib/ruby/gems/2.5.0/gems/async-io-1.17.2/lib/async/io/host_endpoint.rb:57 - execution expired 11.84s: [3933] Request timed out! : <2> Time to process request: 5.01667s 11.85s: <2> Writing 28 bytes response to client via UDP... Exception
IOError' at C:/plong/Ruby25-x64/lib/ruby/2.5.0/socket.rb:321 - closed stream
11.85s: <> UDP response failed: #<IOError: closed stream>!
11.86s: <Async::Reactor:0x2b63260 stopped=false>
: Exiting run-loop because finished.
E:> log.txt
the root cause is that rubydns got an udp port unreachable icmp packet. if get an unreachable packet, rubydns can't receive udp requests anymore, it throws an exception and quit.
Interesting. It could be nice to start trying to get this stuff working on Windows. Unfortunately, I don't have any reason to spend time on it.
Do you know how we should handle Errno::ECONNRESET
in the above backtrace? Ignore it? Or is it something wrong with host configuration/firewall?