Skip to content

Make getaddrinfo an asynchronous lookup with promise and callback variants - #27881

Open
guybedford wants to merge 1 commit into
gbedford/callback-formfrom
gbedford/dns-forms
Open

guybedford wants to merge 1 commit into
gbedford/callback-formfrom
gbedford/dns-forms

Conversation

@guybedford

@guybedford guybedford commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

emscripten_dns_lookup(node, service, hints) is the getaddrinfo body as one __async: ['promise', 'callback'] function: it resolves to a newly allocated addrinfo list (or a negative EAI_* code), synchronously for numeric addresses and errors, and under NODERAWSOCKETS after a node:dns lookup for a hostname, or EAI_AGAIN where sync says the caller cannot wait. getaddrinfo() itself becomes a C wrapper over it; its hand-written ASYNCIFY/pthread dispatch goes away.

emscripten_dns_lookup_promise() and emscripten_dns_lookup_callback() are its _promise and _callback variants, so a real DNS lookup can be awaited without blocking from any stack: as an em_promise_t, or through callback(err, result, arg) on the calling thread (err is never set: a failed lookup is an EAI_* result). All three are declared in emscripten.h, so gen_sig_info generates their signatures as usual. Supersedes #27742.

intptr_t emscripten_dns_lookup(const char *name, const char *service, const struct addrinfo *hints);
em_promise_t emscripten_dns_lookup_promise(const char *name, const char *service, const struct addrinfo *hints);
void emscripten_dns_lookup_callback(const char *name, const char *service, const struct addrinfo *hints,
                                    void (*callback)(bool err, intptr_t result, void *arg), void *arg);

Tests: other.test_dns_lookup_async, sockets_node.test_noderawsockets_dns_async (with PROXY_TO_PTHREAD); existing getaddrinfo tests unchanged.

Made with AI assistance under my review

@guybedford
guybedford added this pull request to stack #27882 October 6, 2026 01:24
@guybedford
guybedford marked this pull request as ready for review October 6, 2026 01:25
@guybedford
guybedford removed this pull request from stack #27882 October 6, 2026 19:38
@guybedford
guybedford added this pull request to stack #27894 October 6, 2026 19:38
@guybedford
guybedford force-pushed the gbedford/dns-forms branch 2 times, most recently from 41c1fe6 to 4048dcd Compare October 7, 2026 01:11
@guybedford
guybedford removed this pull request from stack #27894 October 8, 2026 00:03
@guybedford
guybedford changed the base branch from gbedford/async-canwait to gbedford/fd-form October 8, 2026 00:03
@guybedford
guybedford added this pull request to stack #27923 October 8, 2026 00:03
@guybedford
guybedford force-pushed the gbedford/dns-forms branch 2 times, most recently from 646efed to cd1a59d Compare October 9, 2026 16:56
@guybedford
guybedford force-pushed the gbedford/dns-forms branch 2 times, most recently from a264576 to 1034feb Compare October 12, 2026 23:15
@guybedford
guybedford removed this pull request from stack #27923 October 12, 2026 23:15
@guybedford
guybedford changed the base branch from gbedford/fd-form to gbedford/callback-form October 12, 2026 23:15
@guybedford
guybedford added this pull request to stack #27955 October 12, 2026 23:15
@guybedford guybedford changed the title Make getaddrinfo an asynchronous lookup with fd and promise variants Make getaddrinfo an asynchronous lookup with promise and callback variants Oct 12, 2026
@guybedford
guybedford removed this pull request from stack #27955 October 12, 2026 23:39
@guybedford
guybedford added this pull request to stack #27957 October 12, 2026 23:40
@guybedford
guybedford removed this pull request from stack #27957 October 12, 2026 23:40
@guybedford
guybedford added this pull request to stack #27958 October 12, 2026 23:41
…iants

emscripten_dns_lookup(node, service, hints) is the getaddrinfo body as one
__async: ['promise', 'callback'] function: it resolves to a newly allocated addrinfo list (or
a negative EAI_* code), synchronously for numeric addresses and errors, and
under NODERAWSOCKETS after a node:dns lookup for a hostname, or EAI_AGAIN
where the caller cannot wait. getaddrinfo() itself becomes a C wrapper over
it; the hand-written dispatch goes away.

emscripten_dns_lookup_promise() and emscripten_dns_lookup_callback() are its
variants, so a real DNS lookup can be awaited without blocking from any
stack: as an em_promise_t, or a callback on the calling thread.

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