Real DNS resolution for getaddrinfo under -sNODERAWSOCKETS - #27693
Open
guybedford wants to merge 1 commit into
Open
Real DNS resolution for getaddrinfo under -sNODERAWSOCKETS#27693guybedford wants to merge 1 commit into
guybedford wants to merge 1 commit into
Conversation
/etc/hosts entries (read through the emscripten FS) resolve synchronously, other hostnames resolve via node:dns, blocking where the calling stack can wait (a proxied pthread via PROXY_SYNC_ASYNC, ASYNCIFY/JSPI by suspending) and returning EAI_AGAIN otherwise. Results may be a linked list, which freeaddrinfo now frees in full.
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 gives
getaddrinfo()real name resolution under-sNODERAWSOCKETS. Split out from #27182, which also added a new asynchronous DNS API; this PR is only the change to the existing blocking API, allowing any async API work to follow separately.Previously every hostname resolved to a fake
172.29.x.xaddress, which is fine for the websocket proxy transport but not for real Node.js sockets, where the address has to be connectable./etc/hostsentries (read fresh through the emscripten FS, so MEMFS or a mounted file works) resolve synchronously.node:dns. The lookup is asynchronous, sogetaddrinfoblocks by returning a Promise where the calling stack can wait on it: a sync-proxied pthread (PROXY_SYNC_ASYNC, e.g.main()underPROXY_TO_PTHREAD), orASYNCIFY/JSPIby suspending. Numeric and/etc/hostsresults still return synchronously, soJSPIdoes not pay a microtask on those.EAI_AGAIN.addrinfolinked list (multiple/etc/hostsentries, multiple DNS records,AF_UNSPEC), andfreeaddrinfowalks the whole chain.Everything is gated on
NODERAWSOCKETS; without itgetaddrinfois unchanged.Implementation-wise the existing body becomes
$doGetAddrInfo, which returns either anEAI_*code or a thunk producing a Promise of one, andgetaddrinfois a thin dispatcher on that. The thunk form keeps theASYNCIFYrewind re-invocation from starting a second lookup.Tested with
test_noderawsockets_dns(numeric,/etc/hostsaliases and multi-address lists across families,EAI_AGAINsingle-threaded),test_noderawsockets_dns_blockingunderPROXY_TO_PTHREADandtest_noderawsockets_dns_blocking_jspi, plusASYNCIFYandASYNCIFY+PROXY_TO_PTHREADmanually.Made with AI assistance under my review