Skip to content

Commit

Permalink
[eas-cli] Improve reliability of update asset presigned upload requests
Browse files Browse the repository at this point in the history
  • Loading branch information
wschurman committed Aug 16, 2022
1 parent 8c4d7a6 commit 28d7b4e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/eas-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"ora": "5.1.0",
"pkg-dir": "4.2.0",
"promise-limit": "2.7.0",
"promise-retry": "2.0.1",
"prompts": "2.4.2",
"qrcode-terminal": "0.12.0",
"resolve-from": "5.0.0",
Expand Down Expand Up @@ -89,6 +90,7 @@
"@types/mime": "2.0.3",
"@types/node-fetch": "2.6.2",
"@types/node-forge": "1.0.4",
"@types/promise-retry": "1.1.3",
"@types/prompts": "2.0.14",
"@types/semver": "7.3.10",
"@types/tar": "6.1.2",
Expand Down
32 changes: 32 additions & 0 deletions packages/eas-cli/src/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import FormData from 'form-data';
import fs from 'fs-extra';
import { Response } from 'node-fetch';
import nullthrows from 'nullthrows';
import promiseRetry from 'promise-retry';
import { URL } from 'url';

import fetch from './fetch';
Expand Down Expand Up @@ -31,6 +32,37 @@ export async function uploadWithPresignedPostAsync(
file: string,
presignedPost: PresignedPost,
handleProgressEvent?: ProgressHandler
): Promise<Response> {
return await promiseRetry(
async retry => {
let response: Response;
try {
response = await uploadWithPresignedPostInternalAsync(
file,
presignedPost,
handleProgressEvent
);
} catch (e: any) {
return retry(e);
}

if (!response.ok) {
return retry(new Error(`Presigned post responsed with a ${response.status}`));
}

return response;
},
{
retries: 3,
factor: 2,
}
);
}

export async function uploadWithPresignedPostInternalAsync(
file: string,
presignedPost: PresignedPost,
handleProgressEvent?: ProgressHandler
): Promise<Response> {
const fileStat = await fs.stat(file);
const fileSize = fileStat.size;
Expand Down
14 changes: 13 additions & 1 deletion yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 28d7b4e

Please sign in to comment.