Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions ext/net/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,10 @@ pub enum DnsRecordData {
pub struct DnsRecordWithTtl {
#[to_v8(serde)]
pub data: DnsRecordData,
/// Record type name, populated for ANY queries to distinguish
/// untagged string variants (A vs AAAA vs NS vs PTR vs CNAME).
#[to_v8(serde)]
pub record_type: Option<String>,
pub ttl: u32,
}

Expand Down Expand Up @@ -974,7 +978,7 @@ pub async fn op_dns_resolve(
cancel_rid,
} = args;

let (config, mut opts) = if let Some(name_server) =
let (config, opts) = if let Some(name_server) =
options.as_ref().and_then(|o| o.name_server.as_ref())
{
let group = NameServerConfigGroup::from_ips_clear(
Expand All @@ -993,14 +997,6 @@ pub async fn op_dns_resolve(
system_conf::read_system_conf()?
};

// When a cancel handle is provided, use a short resolver timeout so
// that hickory's background connection tasks clean up quickly after
// cancellation (they are not aborted by the cancel handle itself).
if cancel_rid.is_some() {
opts.timeout = std::time::Duration::from_secs(1);
opts.attempts = 1;
}

{
let mut s = state.borrow_mut();
let perm = s.borrow_mut::<PermissionsContainer>();
Expand Down Expand Up @@ -1066,10 +1062,22 @@ pub async fn op_dns_resolve(
.records()
.iter()
.filter_map(|rec| {
let r = format_rdata(record_type)(rec.data()).transpose();
let is_any = record_type == RecordType::ANY;
// For ANY queries, use each record's actual type for formatting
let effective_type = if is_any {
rec.record_type()
} else {
record_type
};
let r = format_rdata(effective_type)(rec.data()).transpose();
r.map(|maybe_data| {
maybe_data.map(|data| DnsRecordWithTtl {
data,
record_type: if is_any {
Some(effective_type.to_string())
} else {
None
},
ttl: rec.ttl(),
})
})
Expand Down
12 changes: 11 additions & 1 deletion ext/node/polyfills/internal/dns/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,21 @@ export function validateTries(options?: { tries?: number }) {
return tries;
}

export function validateMaxTimeout(
options?: { maxTimeout?: number },
): number {
if (options?.maxTimeout === undefined) return -1; // no cap
validateInt32(options.maxTimeout, "options.maxTimeout", 0, 2 ** 31 - 1);
return options.maxTimeout;
}

export interface ResolverOptions {
timeout?: number | undefined;
/**
* @default 4
*/
tries?: number;
maxTimeout?: number | undefined;
}

/**
Expand Down Expand Up @@ -288,7 +297,8 @@ export class Resolver {
constructor(options?: ResolverOptions) {
const timeout = validateTimeout(options);
const tries = validateTries(options);
this._handle = new ChannelWrap(timeout, tries);
const maxTimeout = validateMaxTimeout(options);
this._handle = new ChannelWrap(timeout, tries, maxTimeout);
}

cancel() {
Expand Down
Loading
Loading