Skip to content

Commit

Permalink
fix: removed p-timeout usage
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Aug 5, 2024
1 parent 33e8ba9 commit a5f03dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
17 changes: 7 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const ipaddr = require('ipaddr.js');
const isStream = require('is-stream');
const mergeOptions = require('merge-options');
const pMap = require('p-map');
const pTimeout = require('p-timeout');
const pWaitFor = require('p-wait-for');
const packet = require('dns-packet');
const semver = require('semver');
Expand Down Expand Up @@ -109,8 +108,6 @@ class Tangerine extends dns.promises.Resolver {
let err;
if (errors.length === 1) {
err = errors[0];
} else if (errors.every((e) => e instanceof pTimeout.TimeoutError)) {
err = errors[0];
} else {
err = new Error(
[...new Set(errors.map((e) => e.message).filter(Boolean))].join('; ')
Expand Down Expand Up @@ -1043,7 +1040,7 @@ class Tangerine extends dns.promises.Resolver {
//
async #request(pkt, server, abortController, timeout = this.options.timeout) {
// safeguard in case aborted
if (abortController?.signal?.aborted) return;
abortController?.signal?.throwIfAborted();

let localAddress;
let localPort;
Expand All @@ -1067,15 +1064,17 @@ class Tangerine extends dns.promises.Resolver {
// <https://github.com/hildjj/dohdec/blob/43564118c40f2127af871bdb4d40f615409d4b9c/pkg/dohdec/lib/doh.js#L117-L120>
if (this.options.requestOptions.method.toLowerCase() === 'get') {
if (!dohdec) await pWaitFor(() => Boolean(dohdec));
// safeguard in case aborted
abortController?.signal?.throwIfAborted();
url += `?dns=${dohdec.DNSoverHTTPS.base64urlEncode(pkt)}`;
} else {
options.body = pkt;
}

debug('request', { url, options });
const response = await pTimeout(this.request(url, options), timeout, {
signal: abortController.signal
});
const t = setTimeout(() => abortController.abort(), timeout);
const response = await this.request(url, options);
clearTimeout(t);
return response;
}

Expand Down Expand Up @@ -1237,9 +1236,7 @@ class Tangerine extends dns.promises.Resolver {
const err = this.constructor.createError(
name,
rrtype,
_err instanceof pTimeout.TimeoutError || _err.name === 'TimeoutError'
? dns.TIMEOUT
: _err.code,
_err.code,
_err.errno
);
// then map it to dns.CONNREFUSED
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"is-stream": "2.0.1",
"merge-options": "3.0.4",
"p-map": "4",
"p-timeout": "4",
"p-wait-for": "3",
"port-numbers": "6.0.1",
"private-ip": "^3.0.2",
Expand Down

0 comments on commit a5f03dc

Please sign in to comment.