Skip to content

Commit

Permalink
fix: attempt to fix uncaught exception per <nodejs/undici#3353>
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Aug 5, 2024
1 parent 814fb4b commit 2351447
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 27 deletions.
4 changes: 2 additions & 2 deletions app/models/domains.js
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ async function verifySMTP(domain, resolver, purgeCache = true) {
retries: 1
});
// consume body
await response.body.dump();
if (!response?.signal?.aborted) await response.body.dump();
},
{ concurrency }
);
Expand Down Expand Up @@ -1436,7 +1436,7 @@ async function getVerificationResults(domain, resolver, purgeCache = false) {
retries: 1
});
// consume body
await response.body.dump();
if (!response?.signal?.aborted) await response.body.dump();
},
{ concurrency }
);
Expand Down
13 changes: 1 addition & 12 deletions helpers/retry-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
const undici = require('undici');
const delay = require('delay');
const ms = require('ms');
const isStream = require('is-stream');

const isRetryableError = require('./is-retryable-error');
const logger = require('./logger');

class RetryClient extends undici.Client {
constructor(opts) {
Expand All @@ -35,16 +33,6 @@ class RetryClient extends undici.Client {
const response = await this._request(options);

// <https://github.com/nodejs/undici/issues/3353#issuecomment-2184635954>

if (
response?.body &&
isStream(response.body) &&
typeof response.body.on === 'function'
)
response.body.on('error', (err) => {
logger.error(err, { response });
});

// the error code is between 200-400 (e.g. 302 redirect)
// in order to mirror the behavior of `throwOnError` we will re-use the undici errors
// <https://github.com/nodejs/undici/issues/2093>
Expand All @@ -62,6 +50,7 @@ class RetryClient extends undici.Client {
throw err;
}

response.signal = options.signal;
return response;
} catch (err) {
if (count >= retries || !isRetryableError(err)) throw err;
Expand Down
13 changes: 1 addition & 12 deletions helpers/retry-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
const undici = require('undici');
const delay = require('delay');
const ms = require('ms');
const isStream = require('is-stream');

const isRetryableError = require('./is-retryable-error');
const logger = require('./logger');

async function retryRequest(url, opts = {}, count = 1) {
try {
Expand All @@ -25,16 +23,6 @@ async function retryRequest(url, opts = {}, count = 1) {
const response = await undici.request(url, opts);

// <https://github.com/nodejs/undici/issues/3353#issuecomment-2184635954>

if (
response?.body &&
isStream(response.body) &&
typeof response.body.on === 'function'
)
response.body.on('error', (err) => {
logger.error(err, { response });
});

// the error code is between 200-400 (e.g. 302 redirect)
// in order to mirror the behavior of `throwOnError` we will re-use the undici errors
// <https://github.com/nodejs/undici/issues/2093>
Expand All @@ -53,6 +41,7 @@ async function retryRequest(url, opts = {}, count = 1) {
throw err;
}

response.signal = opts.signal;
return response;
} catch (err) {
if (count >= opts.retries || !isRetryableError(err)) throw err;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
"striptags": "3.2.0",
"superagent": "8.1.2",
"sweetalert2": "8.19.1",
"tangerine": "1.5.7",
"tangerine": "1.5.8",
"titleize": "2",
"tsdav": "2.1.1",
"twilio": "4.23.0",
Expand Down

0 comments on commit 2351447

Please sign in to comment.