Add emscripten_dns_lookup_async / emscripten_dns_lookup_result - #27742
Open
guybedford wants to merge 1 commit into
Open
guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
guybedford
force-pushed
the
dns-async
branch
from
September 18, 2026 04:08
feebe62 to
85df785
Compare
An asynchronous getaddrinfo that completes through a pollable fd, so a real node:dns lookup under -sNODERAWSOCKETS can be awaited without blocking from any stack. The getaddrinfo body becomes $getAddrInfo, which allocates nothing and returns a descriptor; $writeAddrInfo mints the addrinfo list at the point ownership passes to the caller.
guybedford
force-pushed
the
dns-async
branch
from
September 18, 2026 05:39
85df785 to
1922c3d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an asynchronous
getaddrinfoon top of thegetaddrinfobody from #27693, so a real DNS lookup under-sNODERAWSOCKETScan be awaited without blocking from any stack. Recreates the async API from #27182 on the landed approach.getaddrinfo()underNODERAWSOCKETScan only wait for anode:dnslookup from a sync-proxied pthread or withASYNCIFY/JSPI; on the main thread of a plain build it returnsEAI_AGAIN. Event-loop reactors need a non-blocking form.emscripten_dns_lookup_async(node, service, hints)takes the same inputs and returns an fd that becomes readable (poll/select/epoll) once the lookup completes; numeric addresses and validation errors are readable on return. A pending lookup holds the runtime like a timer.emscripten_dns_lookup_result(fd, &res)reads the outcome:0with a newly allocatedaddrinfolist in*res(freed withfreeaddrinfo), anEAI_*code, orEAI_AGAINwhile pending. Nothing is allocated until a result is read, so the fd owns no C memory:dupshares the lookup andclosehas nothing to free.polland wait-queue node, so it needs nothing fromSOCKFS. WithoutNODERAWSOCKETSthe API works the same, resolving synchronously.The
getaddrinfobody becomes$getAddrInfo, which allocates nothing and returns anEAI_*code or a descriptor (with alookupthunk for a hostname underNODERAWSOCKETS);$writeAddrInfomints theaddrinfolist at the point ownership passes to the caller.getaddrinfokeeps its proxied /Asyncify.handleAsync/EAI_AGAINdispatch unchanged.Tests:
sockets_node.test_noderawsockets_dns_async(withPROXY_TO_PTHREAD: numeric and error results readable at once, repeated reads each minting their own list, close without reading,dupsharing the lookup, close while pending, and a reallocalhostlookup awaited via non-blockingpollretries from the main thread or a blockingpollfrom the pthread) andother.test_dns_lookup_asyncfor the default build.Made with AI assistance under my review