Skip to content

Unexpected exceptions when making parallel queries across threads or fibers #218

Description

@zarqman

In HEAD (after 1.73.1), recent changes to add_config_nameservers appear to have created a race condition when making 2 or more parallel queries across threads or fibers.

Running on HEAD, but with the add_config_nameservers from 1.73.1 works, and is what was actually tested for the "1.73.1" column below.

The error exposes itself 2 different ways depending on the nature of the Resolver config.

resolver 1.37.1 HEAD
r1 (default config) works ArgumentError: No valid nameservers found in config
r2 (with :config_info) works Dnsruby::ResolvTimeout: Query timed out

Reproduction script:

#!/usr/bin/env ruby
$: << './lib'
require 'dnsruby'

  # without config options
  #   1st query (A) works
  #   2nd query (AAAA) raises: ArgumentError: No valid nameservers found in config
  # note: this runs add_config_nameservers 2x in my environment
  #   there are 2x 'nameserver x.x.x.x' in my resolv.conf (1 ip4, 1 ip6); unsure if related
r1 = Dnsruby::Resolver.new

  # with config_info
  #   1st query (A) works
  #   2nd query (AAAA) raises: Dnsruby::ResolvTimeout: Query timed out
  # note: this runs add_config_nameservers 1x in my environment
r2 = Dnsruby::Resolver.new(
      config_info: {
        # contents here doesn't matter; even setting to {} is enough to cause ResolvTimeout
        apply_domain: false,
        apply_search_list: false,
      },
      query_timeout: 3, # make the timeout faster
    )

{r1:, r2:}.each do |name, r|
  puts "#{name} ----"
  %w(A AAAA).map do |type|
    Thread.new do
      ans = r.query('a.root-servers.net.', type).answer
      puts "#{'%-4s' % type}: #{ans.join}"
    rescue
      puts "Exception for #{type}: #{$!.inspect}"
    end
  end.map(&:join)
end

Perhaps the whole set of work from creating PacketSender's to assigning @single_resolvers to error checking all need to be wrapped inside the mutex again?

Activity

  1. alexdalitz commented on Jan 12, 2026

    @alexdalitz
    Owner

    Hi @zarqman Thanks for raising this issue!

    I think I've fixed the config_info issue on master. Your script works fine for me here - could you please give it a go and let me know if it works for you now?

  2. zarqman commented on Jan 12, 2026

    @zarqman
    ContributorAuthor

    @alexdalitz, yes, it works now with 8814c29. Thanks!

  3. alexdalitz commented on Jan 13, 2026

    @alexdalitz
    Owner

    @zarqman Thanks for this!
    I'll be looking to make a new release as soon as the other open issue is confirmed fixed. I'll leave this issue open for now, and ping when I make a release.
    Thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions