Something went wrong. Try again.
javascript for 🐜's, a tiny runtime with big ambitions antjs.org
Something went wrong. Try again.
4.6 kB · 92 lines
Markdown
at master
Node dns Module #
Status: active Last reviewed: 2026-10-15 Owner: theMackabu
Goal #
Ship Node's dns and dns/promises for 16.1 (issue #113: @redis/client
requires dns/promises), alongside assert/strict. Every DNS operation runs
on the isolate's event loop; nothing blocks the JS thread.
Starting point #
src/modules/dns.c exposed only dns.promises.lookup and
dns.promises.resolve. lookup called getaddrinfo synchronously and
ignored its options; resolve drove c-ares through a blocking select loop
and rejected with plain errors. There was no callback API, no dns/promises
specifier, no Resolver, and no error constants.
Scope #
lookup(hostname[, options], cb)andlookupService(address, port, cb)throughuv_getaddrinfo/uv_getnameinfo. Options:family(0, 4, 6, 'IPv4', 'IPv6'),all,order('verbatim', 'ipv4first', 'ipv6first'),verbatim,hints(ADDRCONFIG,V4MAPPED,ALL). IP literals resolve without a system call, as in Node.resolveandresolve4/6(with{ ttl }),resolveAny,resolveCaa,resolveCname,resolveMx,resolveNaptr,resolveNs,resolvePtr,resolveSoa,resolveSrv,resolveTlsa,resolveTxt,reverse.getServers,setServers,setDefaultResultOrder,getDefaultResultOrder, error code constants,ADDRCONFIG,V4MAPPED,ALL.Resolver(callback) andpromises.Resolverwithcancel(),setLocalAddress(),getServers()/setServers()and constructor optionstimeoutandtries.dns/promisesis the same object asdns.promises.
Design #
- Static data. Record types (name, c-ares type, method, Node
syscall) live in the X-macro listinclude/dns/record_types.h; c-ares status to Node code mapping lives ininclude/dns/error_codes.h. - c-ares on libuv. Each channel registers
ARES_OPT_SOCK_STATE_CB; the callback starts or stops auv_poll_tper socket and callsares_process_fd. Auv_timer_tre-armed fromares_timeout()handles retries and timeouts. No c-ares event thread: callbacks must run on the isolate's thread. - Records are parsed with the
ares_dns_record_tAPI (ares_query_dnsrec), not the deprecatedares_parse_*_replyfunctions. One answer-section walk serves every type, including TTLs andANY. - Ownership. Each isolate owns a lazily created default channel and the
lists
js->dns_channelsandjs->dns_requests(list.h). A request pins its promise or callback, its hostname and its owningResolver, andgc_mark_dnsmarks them. AResolverobject owns its channel; its finalizer destroys the channel, and pending queries keep the object alive. - Delivery. Promise and callback forms share one completion path. Callback
delivery follows
timer_callback:GC_UV_CALLBACK(), pin,sv_vm_call, report uncaught exceptions, drain microtasks. - Teardown.
cleanup_dns_moduleruns injs_destroybeforeAnt_Loop_Drain: it marks the isolate as tearing down so completions skip JS, destroys channels (c-ares answersARES_EDESTRUCTION), cancelsuv_getaddrinforequests and closes poll and timer handles.
Decision log #
- Errors match Node:
getaddrinfo ENOTFOUND <host>witherrno,code,syscall,hostname; resolver errors usequery<Type>/getHostByAddrsyscalls;EAI_NONAME/EAI_NODATAmap toENOTFOUNDlike Node. - Default result order is
verbatim(Node 17+). - Ant has no
dgram, so resolver tests start a small Python UDP DNS server and skip whenpython3is missing.lookuptests uselocalhostand IP literals only; no test touches the network.
Validation status #
assert/strictis done (tests/test_assert_strict.cjs).- dns is implemented in
src/modules/dns/(request.c,lookup.c,channel.c,query.c,module.c).tests/test_dns_lookup.cjspasses on Ant and Node.tests/test_dns_resolver.cjspasses on Ant; Node fails only itsresolveAnycheck, because Node returns null entries and dropstypefrom TLSA records there. Ant groupsresolveAnyrecords in Node's type order. - Probes: 600 concurrent queries, 3000 short-lived
Resolvers under allocation churn (open fds 11 before, 13 after), andprocess.exit()with queries pending all finish cleanly. test_io_error_boundary_audit.cjsandtest_io_handled_errors.cjsasserted the old non-Node behavior (rejections forlookup(),lookup(42)and an invalidrrtype); they now assert Node's results.
Follow-ups #
dgramwould let the DNS fixture be written in JS.