tangerine 1.5.7 → 1.5.8

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.
Files changed (2) hide show
  1. package/index.js +25 -26
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1043,7 +1043,7 @@ class Tangerine extends dns.promises.Resolver {
1043
1043
  //
1044
1044
  async #request(pkt, server, abortController, timeout = this.options.timeout) {
1045
1045
  // safeguard in case aborted
1046
- if (abortController.signal.aborted) return;
1046
+ if (abortController?.signal?.aborted) return;
1047
1047
 
1048
1048
  let localAddress;
1049
1049
  let localPort;
@@ -1129,31 +1129,33 @@ class Tangerine extends dns.promises.Resolver {
1129
1129
  const statusCode = response.status || response.statusCode;
1130
1130
  debug('response', { statusCode, headers });
1131
1131
 
1132
- // <https://github.com/nodejs/undici/issues/3353#issuecomment-2184635954>
1133
- // eslint-disable-next-line max-depth
1134
- if (body && isStream(body) && typeof body.on === 'function')
1135
- body.on('error', (err) => {
1136
- this.options.logger.error(err, { response });
1137
- });
1138
-
1139
1132
  // eslint-disable-next-line max-depth
1140
1133
  if (body && statusCode >= 200 && statusCode < 300) {
1141
1134
  // <https://sindresorhus.com/blog/goodbye-nodejs-buffer>
1142
- buffer = Buffer.isBuffer(body)
1143
- ? body
1144
- : // eslint-disable-next-line no-await-in-loop
1145
- await getStream.buffer(body);
1146
- // <https://github.com/nodejs/undici/issues/3353>
1147
- // eslint-disable-next-line no-await-in-loop, max-depth
1148
- if (body && typeof body.dump === 'function') await body.dump();
1149
- // NOTE: we don't need to do this (causes uncaught exception)
1150
- // if (!abortController.signal.aborted) abortController.abort();
1135
+ // eslint-disable-next-line max-depth
1136
+ if (Buffer.isBuffer(body)) buffer = body;
1137
+ else if (typeof body.arrayBuffer === 'function')
1138
+ // eslint-disable-next-line no-await-in-loop
1139
+ buffer = Buffer.from(await body.arrayBuffer());
1140
+ // eslint-disable-next-line no-await-in-loop
1141
+ else if (isStream(body)) buffer = await getStream.buffer(body);
1142
+ else {
1143
+ const err = new TypeError('Unsupported body type');
1144
+ err.body = body;
1145
+ throw err;
1146
+ }
1147
+
1151
1148
  break;
1152
1149
  }
1153
1150
 
1154
1151
  // <https://github.com/nodejs/undici/issues/3353>
1155
- // eslint-disable-next-line no-await-in-loop, max-depth
1156
- if (body && typeof body.dump === 'function') await body.dump();
1152
+ if (
1153
+ !abortController?.signal?.aborted &&
1154
+ body &&
1155
+ typeof body.dump === 'function'
1156
+ )
1157
+ // eslint-disable-next-line no-await-in-loop
1158
+ await body.dump();
1157
1159
 
1158
1160
  // <https://github.com/nodejs/undici/blob/00dfd0bd41e73782452aecb728395f354585ca94/lib/core/errors.js#L47-L58>
1159
1161
  const message =
@@ -1173,14 +1175,13 @@ class Tangerine extends dns.promises.Resolver {
1173
1175
  // NOTE: if NOTFOUND error occurs then don't attempt further requests
1174
1176
  // <https://nodejs.org/api/dns.html#dnssetserversservers>
1175
1177
  //
1176
- // eslint-disable-next-line max-depth
1178
+
1177
1179
  if (err.code === dns.NOTFOUND) throw err;
1178
1180
 
1179
- // eslint-disable-next-line max-depth
1180
1181
  if (err.status >= 429) ipErrors.push(err);
1181
1182
 
1182
1183
  // break out of the loop if status code was not retryable
1183
- // eslint-disable-next-line max-depth
1184
+
1184
1185
  if (
1185
1186
  !(
1186
1187
  err.statusCode &&
@@ -1231,8 +1232,6 @@ class Tangerine extends dns.promises.Resolver {
1231
1232
  // https://github.com/mafintosh/dns-packet/issues/72
1232
1233
  return packet.decode(buffer);
1233
1234
  } catch (_err) {
1234
- // NOTE: we don't need to do this (causes uncaught exception)
1235
- // if (!abortController.signal.aborted) abortController.abort();
1236
1235
  debug(_err, { name, rrtype, ecsSubnet });
1237
1236
  if (this.options.returnHTTPErrors) throw _err;
1238
1237
  const err = this.constructor.createError(
@@ -1258,7 +1257,7 @@ class Tangerine extends dns.promises.Resolver {
1258
1257
  for (const abortController of this.abortControllers) {
1259
1258
  if (!abortController.signal.aborted) {
1260
1259
  try {
1261
- abortController.abort();
1260
+ abortController.abort('Cancel invoked');
1262
1261
  } catch (err) {
1263
1262
  this.options.logger.debug(err);
1264
1263
  }
@@ -1281,7 +1280,7 @@ class Tangerine extends dns.promises.Resolver {
1281
1280
  'abort',
1282
1281
  () => {
1283
1282
  try {
1284
- abortController.abort();
1283
+ abortController.abort('Parent abort controller aborted');
1285
1284
  } catch (err) {
1286
1285
  this.options.logger.debug(err);
1287
1286
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tangerine",
3
3
  "description": "Tangerine is the best Node.js drop-in replacement for dns.promises.Resolver using DNS over HTTPS (\"DoH\") via undici with built-in retries, timeouts, smart server rotation, AbortControllers, and caching support for multiple backends (with TTL and purge support).",
4
- "version": "1.5.7",
4
+ "version": "1.5.8",
5
5
  "author": "Forward Email (https://forwardemail.net)",
6
6
  "bugs": {
7
7
  "url": "https://github.com/forwardemail/nodejs-dns-over-https-tangerine/issues"