Skip to content

Commit

Permalink
fix: always retry s3 upload (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanshaw committed Aug 2, 2022
1 parent 0d6a0c3 commit 99e7ce5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
18 changes: 7 additions & 11 deletions packages/api/src/utils/s3-uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,15 @@ export class S3Uploader {
}

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

return new URL(key, this._baseUrl.toString())
Expand Down
21 changes: 20 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14818,6 +14818,25 @@ nextra@^2.0.0-beta.5:
remark-mdx-code-meta "^1.0.0"
slash "^3.0.0"

nft.storage@^6.0.0:
version "6.4.1"
resolved "https://registry.yarnpkg.com/nft.storage/-/nft.storage-6.4.1.tgz#262faa3ba67970cbdd48480aa048d96671c6ccb4"
integrity sha512-UwZ+QgDCr58X+vHN4BydqdB89M8Vaza+vkWR9RatC3rXuDfIyYE5T7oOV53tbiuhA8x5Yi56tlG3NI8wLfOO1A==
dependencies:
"@ipld/car" "^3.2.3"
"@ipld/dag-cbor" "^6.0.13"
"@web-std/blob" "^3.0.1"
"@web-std/fetch" "^3.0.3"
"@web-std/file" "^3.0.0"
"@web-std/form-data" "^3.0.0"
carbites "^1.0.6"
ipfs-car "^0.6.2"
it-pipe "^1.1.0"
multiformats "^9.6.4"
p-retry "^4.6.1"
streaming-iterables "^6.0.0"
throttled-queue "^2.1.2"

nice-try@^1.0.4:
version "1.0.5"
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
Expand Down Expand Up @@ -19758,7 +19777,7 @@ ua-parser-js@^1.0.2:
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-1.0.2.tgz#e2976c34dbfb30b15d2c300b2a53eac87c57a775"
integrity sha512-00y/AXhx0/SsnI51fTc0rLRmafiGOM4/O+ny10Ps7f+j/b8p/ZY11ytMgznXkOVo4GQ+KwQG5UQLkLGirsACRg==

"ucan-storage@^ 1.3.0":
ucan-storage@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/ucan-storage/-/ucan-storage-1.3.0.tgz#b9f3e29fa77da22a636ba5d917f4e747da0a89c8"
integrity sha512-C1PvShqWTg6JzcBAuWDeCsaL6AggwsGWqbvKZ8XdN9csAukQVnA5/kerddhdPrpeoCGnJFfSkvBcPklZzdJ+OQ==
Expand Down

0 comments on commit 99e7ce5

Please sign in to comment.