Skip to content

Avoid AI_ADDRCONFIG netlink path for DNS lookups (#560, #524)#589

Merged
bsergean merged 1 commit into
masterfrom
fix/dns-addrconfig-netlink-crash
Jun 25, 2026
Merged

Avoid AI_ADDRCONFIG netlink path for DNS lookups (#560, #524)#589
bsergean merged 1 commit into
masterfrom
fix/dns-addrconfig-netlink-crash

Conversation

@bsergean

Copy link
Copy Markdown
Collaborator

Fixes #560
Fixes #524

Problem

DNSLookup::getAddrInfo always passed AI_ADDRCONFIG to getaddrinfo:

hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV;

That flag causes two distinct failures:

  • Crash on DNS lookup #560 (crash): on glibc, AI_ADDRCONFIG enumerates the configured interfaces through a netlink socket (__check_pf). Under heavy threaded churn that path can abort the whole process from inside getaddrinfo (__netlink_assert_responseSIGABRT). The reported reproducer connects to 127.0.0.1 — a numeric literal that needs no name resolution at all.
  • Localhost DNS lookup fails without network connection #524 (offline localhost): AI_ADDRCONFIG only returns addresses for families with a configured non-loopback interface. With no network (cable unplugged / no wifi), even localhost fails to resolve.

Fix

  1. Numeric IP literals (detected with the library's inet_pton) now use AI_NUMERICHOST and drop AI_ADDRCONFIG. There's no name to resolve, so glibc skips the netlink enumeration entirely — directly avoiding the Crash on DNS lookup #560 abort for IP hosts, and making literal lookups faster. This covers the exact 127.0.0.1 reproducer.
  2. Real hostnames keep AI_ADDRCONFIG for its intended benefit, but if the first getaddrinfo fails we retry once without it, so loopback-resolving names still work offline (Localhost DNS lookup fails without network connection #524). No new API/config knob required.

Testing

  • Builds clean (-DUSE_TLS=ON -DUSE_OPEN_SSL=ON, CMAKE_CXX_STANDARD 11).
  • Smoke test via DNSLookup::resolve: 127.0.0.1, ::1, 8.8.8.8 (numeric path) and localhost (AI_ADDRCONFIG path) all resolve correctly.

Notes / scope

  • This is the cleanest mitigation for the Crash on DNS lookup #560 reproducer (numeric host → no netlink). For non-numeric hostnames under extreme threaded churn the glibc netlink abort is a deeper libc-level issue; if that surfaces in practice, a follow-up could drop AI_ADDRCONFIG more broadly, but that has IPv4/IPv6 selection trade-offs so I kept this change conservative.
  • Double EBADF Error Callback On DNS Fail #565 (double callback on DNS fail) is a separate auto-reconnection behavior, not addressed here.

🤖 Generated with Claude Code

getAddrInfo always passed AI_ADDRCONFIG to getaddrinfo. That flag has two
problematic consequences:

- On glibc it enumerates the configured interfaces through a netlink socket
  (__check_pf). Under heavy threaded churn this path can abort the whole
  process from inside getaddrinfo (__netlink_assert_response), which is the
  crash reported in #560 -- reproduced while connecting to "127.0.0.1".

- It only returns addresses for families that have a configured, non-loopback
  interface, so a host resolving to loopback (e.g. "localhost") fails to
  resolve when the machine is offline (#524).

Two changes:

1. Detect numeric IP literals (via inet_pton) and use AI_NUMERICHOST instead
   of AI_ADDRCONFIG. There is no name to resolve, so we skip the netlink
   enumeration entirely -- directly avoiding the #560 abort for IP hosts and
   making literal lookups faster.

2. For real hostnames, retry getaddrinfo once without AI_ADDRCONFIG if the
   first attempt fails, so loopback names still resolve when offline (#524).

Smoke-tested: 127.0.0.1, ::1, 8.8.8.8 and localhost all still resolve.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bsergean bsergean merged commit 14a4761 into master Jun 25, 2026
7 checks passed
bsergean added a commit that referenced this pull request Jun 25, 2026
Release of accumulated fixes since v12.0.0: DNS lookup crash/offline
resolution (#589), OpenSSL IP-address cert validation (#588),
case-insensitive Upgrade header (#584), server fd double-close (#585),
fragment buffering optimization (#562), and the install include-dir fix (#582).

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

Crash on DNS lookup Localhost DNS lookup fails without network connection

1 participant