alexdalitz / dnsruby

Dnsruby is a feature-complete DNS(SEC) client for Ruby, as used by many of the world's largest DNS registries and the OpenDNSSEC project
Other
194 stars 77 forks source link

Strange results with two resolver instances #189

Closed svdasein closed 9 months ago

svdasein commented 9 months ago

I'm not sure if I'm doing something wrong here... I'm writing a script to make queries of two separate dns servers at two different IP addresses. I'm setting up for that like this:

server1 = Dnsruby::Resolver.new()
server1.nameserver = opts[:nameserver1]
server1.src_address = opts[:sourceaddr]

server2 = Dnsruby::Resolver.new()
server2.nameserver = opts[:nameserver2]
server2.src_address = opts[:sourceaddr]

And making two calls like this:

res1 = server1.query(pair[0],pair[1])
res2 = server2.query(pair[0],pair[1])

The confusing part is this: If I query the first server for a name that only it has, res1 contains an answer that is correct and also shows answerfrom from the appropriate server. res2 however ALSO contains an answer - it looks remarkably like the answer I just got for server1 - the only difference between the two is that res2's answerfrom is nil.

It seems like the server2 result is somehow picking up the answer from the last question that server1 asked.

Do I need to do this differently or is that "as designed" ?

---- addendum:

I've tried executing the one that should fail first - if I do that I get an NXDOMAIN exception. If I do it in the other order I do not.

Is there a work around for this?

svdasein commented 9 months ago

Ok - I figured this out. For anyone who runs into this, here's the right way:

server1 = Dnsruby::Resolver.new({nameserver: opts[:nameserver1], src_address: opts[:sourceaddr], do_caching: false})
server2 = Dnsruby::Resolver.new({nameserver: opts[:nameserver2], src_address: opts[:sourceaddr], do_caching: false})

The important bit being do_caching: false