From fe6ee5998f8526efb70b9d750641b0089a7a4c85 Mon Sep 17 00:00:00 2001 From: Daniel Ricaud Date: Thu, 6 Apr 2023 18:33:28 -0500 Subject: [PATCH] Added axios retry logic when fetching remote chunk from url (#173) --- lib/package-lock.json | 64 ++++++++++++++++++++++++++++++++++ lib/package.json | 1 + lib/tdf3/src/utils/chunkers.ts | 4 +++ 3 files changed, 69 insertions(+) diff --git a/lib/package-lock.json b/lib/package-lock.json index 987acde7..b51cb881 100644 --- a/lib/package-lock.json +++ b/lib/package-lock.json @@ -11,6 +11,7 @@ "dependencies": { "@aws-sdk/client-s3": "3.197.0", "axios": "^1.2.3", + "axios-retry": "^3.4.0", "browser-fs-access": "^0.31.2", "buffer": "^6.0.3", "buffer-crc32": "^0.2.13", @@ -1805,6 +1806,17 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/runtime": { + "version": "7.21.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", + "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", + "dependencies": { + "regenerator-runtime": "^0.13.11" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@bcoe/v8-coverage": { "version": "0.2.3", "dev": true, @@ -3632,6 +3644,15 @@ "proxy-from-env": "^1.1.0" } }, + "node_modules/axios-retry": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/axios-retry/-/axios-retry-3.4.0.tgz", + "integrity": "sha512-VdgaP+gHH4iQYCCNUWF2pcqeciVOdGrBBAYUfTY+wPcO5Ltvp/37MLFNCmJKo7Gj3SHvCSdL8ouI1qLYJN3liA==", + "dependencies": { + "@babel/runtime": "^7.15.4", + "is-retry-allowed": "^2.2.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "dev": true, @@ -6932,6 +6953,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/is-retry-allowed": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-2.2.0.tgz", + "integrity": "sha512-XVm7LOeLpTW4jV19QSH38vkswxoLud8sQ57YwJVTPWdiaI9I8keEhGFpBlslyVsgdQy4Opg8QOLb8YRgsyZiQg==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-shared-array-buffer": { "version": "1.0.2", "dev": true, @@ -9398,6 +9430,11 @@ "node": ">=6" } }, + "node_modules/regenerator-runtime": { + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" + }, "node_modules/regexp.prototype.flags": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.3.tgz", @@ -13010,6 +13047,14 @@ "js-tokens": "^4.0.0" } }, + "@babel/runtime": { + "version": "7.21.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", + "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", + "requires": { + "regenerator-runtime": "^0.13.11" + } + }, "@bcoe/v8-coverage": { "version": "0.2.3", "dev": true @@ -14383,6 +14428,15 @@ "proxy-from-env": "^1.1.0" } }, + "axios-retry": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/axios-retry/-/axios-retry-3.4.0.tgz", + "integrity": "sha512-VdgaP+gHH4iQYCCNUWF2pcqeciVOdGrBBAYUfTY+wPcO5Ltvp/37MLFNCmJKo7Gj3SHvCSdL8ouI1qLYJN3liA==", + "requires": { + "@babel/runtime": "^7.15.4", + "is-retry-allowed": "^2.2.0" + } + }, "balanced-match": { "version": "1.0.2", "dev": true @@ -16605,6 +16659,11 @@ "has-tostringtag": "^1.0.0" } }, + "is-retry-allowed": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-retry-allowed/-/is-retry-allowed-2.2.0.tgz", + "integrity": "sha512-XVm7LOeLpTW4jV19QSH38vkswxoLud8sQ57YwJVTPWdiaI9I8keEhGFpBlslyVsgdQy4Opg8QOLb8YRgsyZiQg==" + }, "is-shared-array-buffer": { "version": "1.0.2", "dev": true, @@ -18320,6 +18379,11 @@ "version": "2.0.0", "dev": true }, + "regenerator-runtime": { + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==" + }, "regexp.prototype.flags": { "version": "1.4.3", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.3.tgz", diff --git a/lib/package.json b/lib/package.json index 1562a827..7e0ebec1 100644 --- a/lib/package.json +++ b/lib/package.json @@ -65,6 +65,7 @@ "dependencies": { "@aws-sdk/client-s3": "3.197.0", "axios": "^1.2.3", + "axios-retry": "^3.4.0", "browser-fs-access": "^0.31.2", "buffer": "^6.0.3", "buffer-crc32": "^0.2.13", diff --git a/lib/tdf3/src/utils/chunkers.ts b/lib/tdf3/src/utils/chunkers.ts index 33359f5f..11d40bff 100644 --- a/lib/tdf3/src/utils/chunkers.ts +++ b/lib/tdf3/src/utils/chunkers.ts @@ -2,6 +2,10 @@ import axios, { AxiosResponse } from 'axios'; import { Buffer } from 'buffer'; import { createReadStream, readFile, statSync } from 'fs'; import { type AnyTdfStream, isAnyTdfStream } from '../client/tdf-stream.js'; +import axiosRetry from 'axios-retry'; + +// @ts-ignore +axiosRetry(axios, { retries: 3 }); // Retries all idempotent requests (GET, HEAD, OPTIONS, PUT, DELETE) /** * Read data from a seekable stream.