Skip to content

Commit 99e7ce5

Browse files
author
Alan Shaw
authored
fix: always retry s3 upload (#2111)
1 parent 0d6a0c3 commit 99e7ce5

2 files changed

Lines changed: 27 additions & 12 deletions

File tree

packages/api/src/utils/s3-uploader.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,15 @@ export class S3Uploader {
9999
}
100100

101101
try {
102-
await this._s3.send(new PutObjectCommand(cmdParams))
103-
} catch (/** @type {any} */ err) {
104-
if (err.name === 'BadDigest') {
105-
// s3 returns a 400 Bad Request `BadDigest` error if the hash does not match their calculation.
106-
// see: https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html#RESTErrorResponses
107-
// see: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-s3/index.html#troubleshooting
108-
console.log(
109-
'BadDigest: sha256 of data recieved did not match what we sent. Maybe bits flipped in transit. Retrying once.'
110-
)
102+
try {
103+
await this._s3.send(new PutObjectCommand(cmdParams))
104+
} catch (err) {
105+
console.warn('Failed to upload CAR, retrying once...', err)
111106
await this._s3.send(new PutObjectCommand(cmdParams))
112-
} else {
113-
throw err
114107
}
108+
} catch (/** @type {any} */ err) {
109+
// @ts-ignore TS does not know about `cause` yet.
110+
throw new Error('Failed to upload CAR', { cause: err })
115111
}
116112

117113
return new URL(key, this._baseUrl.toString())

yarn.lock

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14818,6 +14818,25 @@ nextra@^2.0.0-beta.5:
1481814818
remark-mdx-code-meta "^1.0.0"
1481914819
slash "^3.0.0"
1482014820

14821+
nft.storage@^6.0.0:
14822+
version "6.4.1"
14823+
resolved "https://registry.yarnpkg.com/nft.storage/-/nft.storage-6.4.1.tgz#262faa3ba67970cbdd48480aa048d96671c6ccb4"
14824+
integrity sha512-UwZ+QgDCr58X+vHN4BydqdB89M8Vaza+vkWR9RatC3rXuDfIyYE5T7oOV53tbiuhA8x5Yi56tlG3NI8wLfOO1A==
14825+
dependencies:
14826+
"@ipld/car" "^3.2.3"
14827+
"@ipld/dag-cbor" "^6.0.13"
14828+
"@web-std/blob" "^3.0.1"
14829+
"@web-std/fetch" "^3.0.3"
14830+
"@web-std/file" "^3.0.0"
14831+
"@web-std/form-data" "^3.0.0"
14832+
carbites "^1.0.6"
14833+
ipfs-car "^0.6.2"
14834+
it-pipe "^1.1.0"
14835+
multiformats "^9.6.4"
14836+
p-retry "^4.6.1"
14837+
streaming-iterables "^6.0.0"
14838+
throttled-queue "^2.1.2"
14839+
1482114840
nice-try@^1.0.4:
1482214841
version "1.0.5"
1482314842
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
@@ -19758,7 +19777,7 @@ ua-parser-js@^1.0.2:
1975819777
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.2.tgz#e2976c34dbfb30b15d2c300b2a53eac87c57a775"
1975919778
integrity sha512-00y/AXhx0/SsnI51fTc0rLRmafiGOM4/O+ny10Ps7f+j/b8p/ZY11ytMgznXkOVo4GQ+KwQG5UQLkLGirsACRg==
1976019779

19761-
"ucan-storage@^ 1.3.0":
19780+
ucan-storage@^1.3.0:
1976219781
version "1.3.0"
1976319782
resolved "https://registry.yarnpkg.com/ucan-storage/-/ucan-storage-1.3.0.tgz#b9f3e29fa77da22a636ba5d917f4e747da0a89c8"
1976419783
integrity sha512-C1PvShqWTg6JzcBAuWDeCsaL6AggwsGWqbvKZ8XdN9csAukQVnA5/kerddhdPrpeoCGnJFfSkvBcPklZzdJ+OQ==

0 commit comments

Comments
 (0)