Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dns cache #2440 #2552

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/core/dns-resolver.js
Expand Up @@ -213,7 +213,7 @@ class DNSResolver {
}

if (cached.length === 0) {
const error = new Error(`cacheableLookup ENOTFOUND ${hostname}`)
const error = new Error(`DNSResolver ENOTFOUND ${hostname}`)
error.code = 'ENOTFOUND'
error.hostname = hostname

Expand Down Expand Up @@ -266,6 +266,10 @@ class DNSResolver {
ignoreNoResultErrors(this._resolve6(hostname, ttl))
])

if (entries[0].status === 'rejected' && entries[1].status === 'rejected') {
throw entries[0].reason
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only throw the first error? Wouldn't it be better to throw an AggregateError that contains both?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing that, using AggregateError and modifying tests


const A = entries[0].status === 'fulfilled' ? entries[0].value : []
const AAAA = entries[1].status === 'fulfilled' ? entries[1].value : []

Expand Down Expand Up @@ -339,7 +343,7 @@ class DNSResolver {
} catch (error) {
this.lookupAsync = async () => {
const cacheError = new Error(
'Cache Error. Please recreate the CacheableLookup instance.'
'Cache Error. Please recreate the DNSResolver instance.'
)
cacheError.cause = error

Expand Down