Skip to content

Opt-in for RFC 6724-compliant host resolution - #482

Open
GoodForOneFare wants to merge 1 commit into
socketry:mainfrom
GoodForOneFare:gordo-async-dns
Open

GoodForOneFare wants to merge 1 commit into
socketry:mainfrom
GoodForOneFare:gordo-async-dns

Conversation

@GoodForOneFare

Copy link
Copy Markdown

Under a fiber scheduler, Ruby hands every hostname lookup to Scheduler#address_resolve, which answers with pure-Ruby Resolv. Resolv only reads /etc/hosts and /etc/resolv.conf, so the same code resolves differently inside and outside Async:

See also #357 and #180.

This keeps Resolv as the default and adds an opt-in that resolves with getaddrinfo on a short-lived thread, without blocking the event loop:

  • ASYNC_SCHEDULER_PLATFORM_RESOLVER=true, or
  • Scheduler.new(platform_resolver: true), or an integer such as platform_resolver: 4 to set the limit.

At most 16 callers (by default) wait on lookups at once per scheduler; further callers wait for a free slot. getaddrinfo can't be cancelled, so a caller that is stopped or times out frees its slot immediately, and the abandoned lookup runs until the system resolver gives up, the same as it would outside the scheduler.

Unlike #454, which reorders Resolv results, this delegates to the system resolver, so lookups honour the same configuration inside and outside Async.

Types of Changes

  • New feature.

Contribution

Under a fiber scheduler, Ruby hands every hostname lookup to `address_resolve`, which answered with pure-Ruby `Resolv`. That only reads `/etc/hosts` and `/etc/resolv.conf`, so the same code resolves differently inside and outside `Async`: macOS `/etc/resolver`, mDNS and `nsswitch.conf` are ignored, and RFC 6724 / `gai.conf` ordering is lost, so IPv4 addresses always come before IPv6 (see socketry#453, socketry#357, socketry#180).

Keep `Resolv` as the default, but resolve with `getaddrinfo` on a short-lived thread when `ASYNC_SCHEDULER_PLATFORM_RESOLVER=true` or `Scheduler.new(platform_resolver: true)`. At most 16 callers (or the limit given to `platform_resolver:`) wait on lookups at once per scheduler. `getaddrinfo` can't be cancelled, so a caller that is stopped or times out frees its slot immediately while the abandoned lookup runs until the system resolver gives up, as it would outside the scheduler.
@GoodForOneFare
GoodForOneFare marked this pull request as ready for review November 4, 2026 19:30

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant