Skip to content

Fix DNS worker lifetime and add a synchronous resolver fallback - #656

Merged
bsergean merged 5 commits into
masterfrom
fix/dns-worker-lifetime
Nov 17, 2026
Merged

bsergean merged 5 commits into
masterfrom
fix/dns-worker-lifetime

Conversation

@bsergean

@bsergean bsergean commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Fix detached resolver ownership and expose the synchronous DNS workaround requested in #364, while preserving cancellable hostname lookups by default.

  • Make the worker entry point and address helper static. Detached jobs receive copied arguments and weak ownership, and access lookup fields only through a successfully locked shared pointer. Remove the extra shared allocation for the thread object.
  • Resolve numeric IPv4/IPv6 addresses inline with AI_NUMERICHOST/AI_NUMERICSERV and no AI_ADDRCONFIG. Check cancellation before and after parsing, and reject already-cancelled hostname requests before creating a worker.
  • Add default-on USE_ASYNC_DNS. Setting it to OFF routes hostname queries through the existing synchronous path, so affected full-static glibc deployments can use the workaround without editing the library. The documentation explains that cancellation/stop must then wait for the system resolver. This does not remove glibc/NSS runtime deployment requirements.
  • Handle empty cancellation callbacks consistently.

Validation: both DNS modes pass 15 assertions, with new local cases finishing under 1 ms. Full plain-socket suite: 31/31 passed; targeted ThreadSanitizer and MinGW compilation checks passed. A controlled ASan/UBSan probe blocked the resolver, cancelled/destroyed its lookup, then released it: 50 workers completed safely after owner destruction. Fully static Linux/glibc executables passed 30 numeric/localhost lookups; the synchronous CMake build also resolves stack-owned hostname lookups with the default API, proving it creates no worker. Strict C++11 warnings-as-errors builds and formatting/diff checks passed. No new unit test sleeps or waits for a network timeout.

Closes #364 by exposing the requested synchronous-resolution fallback. Related to #406, whose application-specific post-message thread growth still needs a current reproduction. Includes the same validated Darwin errno/TSan workaround carried by #651/#653.

@bsergean bsergean changed the title Decouple DNS worker lifetime and resolve numeric addresses inline Fix DNS worker lifetime and add a synchronous resolver fallback Nov 17, 2026
@bsergean
bsergean merged commit fb309ca into master Nov 17, 2026
13 checks passed
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.

Segmentation fault when using static binaries on unix.

1 participant