Skip to content

Commit

Permalink
Log an error if multi-part upload fails
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn committed Jul 3, 2024
1 parent 2d78191 commit 186d76b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions packages/shared/src/async/retryOnFailure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { timeoutAfter } from "./timeoutAfter";
async function retry<T>(
asyncFunction: () => Promise<T>,
backOffStrategy: (iteration: number) => number,
onFail?: (error: unknown, attemptNumber: number) => void,
onFail?: (error: unknown, attemptNumber: number, maxAttempts: number) => void,
maxAttempts: number = 5
): Promise<T> {
let currentAttempt = 0;
Expand All @@ -14,7 +14,7 @@ async function retry<T>(
return await asyncFunction();
} catch (error) {
if (onFail) {
onFail(error, currentAttempt);
onFail(error, currentAttempt, maxAttempts);
}

if (currentAttempt == maxAttempts) {
Expand All @@ -30,7 +30,7 @@ async function retry<T>(

export async function retryWithExponentialBackoff<T>(
asyncFunction: () => Promise<T>,
onFail?: (error: unknown, attemptNumber: number) => void,
onFail?: (error: unknown, attemptNumber: number, maxAttempts: number) => void,
maxTries?: number
): Promise<T> {
const backoff = (iteration: number) => 2 ** iteration * 100 + jitter();
Expand All @@ -40,7 +40,7 @@ export async function retryWithExponentialBackoff<T>(

export async function retryWithLinearBackoff<T>(
asyncFunction: () => Promise<T>,
onFail?: (error: unknown, attemptNumber: number) => void,
onFail?: (error: unknown, attemptNumber: number, maxAttempts: number) => void,
maxTries?: number
): Promise<T> {
const backoff = () => 100 + jitter();
Expand Down
9 changes: 7 additions & 2 deletions packages/shared/src/recording/upload/uploadRecording.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,13 @@ async function uploadRecordingFileInParts({
abortController.signal
);
},
(error: any) => {
logger.debug(`Failed to upload part ${index + 1}; will be retried`, error);
(error: any, attemptNumber: number, maxAttempts: number) => {
let message = `Failed to upload part ${index + 1}`;
if (attemptNumber < maxAttempts && error.code !== "ENOENT") {
message += `; will be retried`;
}
logger.error(message, { error });

if (error.code === "ENOENT") {
throw error;
}
Expand Down

0 comments on commit 186d76b

Please sign in to comment.