@nxtedition/nxt-undici 6.0.2 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/interceptor/dns.js
CHANGED
|
@@ -27,10 +27,10 @@ class Handler extends DecoratorHandler {
|
|
|
27
27
|
|
|
28
28
|
export default () => (dispatch) => {
|
|
29
29
|
const cache = new Map()
|
|
30
|
-
const
|
|
30
|
+
const promises = new Map()
|
|
31
31
|
|
|
32
32
|
function resolve(hostname) {
|
|
33
|
-
let promise =
|
|
33
|
+
let promise = promises.get(hostname)
|
|
34
34
|
if (!promise) {
|
|
35
35
|
promise = resolve4(hostname, { ttl: true })
|
|
36
36
|
.then((records) => {
|
|
@@ -45,9 +45,9 @@ export default () => (dispatch) => {
|
|
|
45
45
|
return next
|
|
46
46
|
})
|
|
47
47
|
.finally(() => {
|
|
48
|
-
|
|
48
|
+
promises.delete(hostname)
|
|
49
49
|
})
|
|
50
|
-
|
|
50
|
+
promises.set(hostname, promise)
|
|
51
51
|
}
|
|
52
52
|
return promise
|
|
53
53
|
}
|
|
@@ -71,7 +71,7 @@ export default () => (dispatch) => {
|
|
|
71
71
|
|
|
72
72
|
if (records == null || records.every((x) => x.stats.errored || x.expires < now)) {
|
|
73
73
|
records = await resolve(hostname)
|
|
74
|
-
} else if (records.some((x) => x.errored || x.expires + 1e3
|
|
74
|
+
} else if (records.some((x) => x.errored || x.expires < now + 1e3)) {
|
|
75
75
|
resolve(hostname).catch(noop)
|
|
76
76
|
}
|
|
77
77
|
|
|
@@ -103,7 +103,9 @@ export default () => (dispatch) => {
|
|
|
103
103
|
{ ...opts, origin, headers: { ...opts.headers, host } },
|
|
104
104
|
new Handler(handler, (err) => {
|
|
105
105
|
record.pending--
|
|
106
|
-
if (err
|
|
106
|
+
if (err == null) {
|
|
107
|
+
record.stats.errored = 0
|
|
108
|
+
} else if (err.name === 'AbortError') {
|
|
107
109
|
// Do nothing...
|
|
108
110
|
} else if (err.statusCode == null || err.statusCode >= 500) {
|
|
109
111
|
record.stats.errored++
|
|
@@ -84,7 +84,7 @@ class Handler extends DecoratorHandler {
|
|
|
84
84
|
|
|
85
85
|
#decorateError(err) {
|
|
86
86
|
try {
|
|
87
|
-
err.url ??= new URL(this.#opts.path, this.#opts.origin).href
|
|
87
|
+
err.url ??= this.#opts.origin ? new URL(this.#opts.path, this.#opts.origin).href : null
|
|
88
88
|
|
|
89
89
|
err.req = {
|
|
90
90
|
method: this.#opts?.method,
|