Skip to content

Commit

Permalink
fix: handle terminal while retrying in RetryScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed Oct 22, 2024
1 parent b82ff1d commit 5999b07
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions packages/hms-video-store/src/transport/RetryScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,7 @@ export class RetryScheduler {
}
}

const timeElapsedSinceError = Date.now() - failedAt;
if (timeElapsedSinceError >= maxRetryTime || hasFailedDependency) {
error.description += `. [${TFC[category]}] Could not recover after ${timeElapsedSinceError} milliseconds`;

if (hasFailedDependency) {
error.description += ` Could not recover all of it's required dependencies - [${(dependencies as Array<TFC>)
.map(dep => TFC[dep])
.toString()}]`;
}
error.isTerminal = true;

const handleTerminalError = (error: HMSException) => {
// @NOTE: Don't reject to throw error for dependencies, use onStateChange
// const taskPromise = this.inProgress.get(category);
this.inProgress.delete(category);
Expand All @@ -140,6 +130,19 @@ export class RetryScheduler {
}

return;
};

const timeElapsedSinceError = Date.now() - failedAt;
if (timeElapsedSinceError >= maxRetryTime || hasFailedDependency) {
error.description += `. [${TFC[category]}] Could not recover after ${timeElapsedSinceError} milliseconds`;

if (hasFailedDependency) {
error.description += ` Could not recover all of it's required dependencies - [${(dependencies as Array<TFC>)
.map(dep => TFC[dep])
.toString()}]`;
}
error.isTerminal = true;
return handleTerminalError(error);
}

if (changeState) {
Expand All @@ -158,11 +161,18 @@ export class RetryScheduler {
taskSucceeded = await this.setTimeoutPromise(task, delay);
} catch (ex) {
taskSucceeded = false;
HMSLogger.w(
this.TAG,
`[${TFC[category]}] Un-caught exception ${(ex as HMSException).name} in retry-task, initiating retry`,
ex,
);
const error = ex as HMSException;

if (error.isTerminal) {
HMSLogger.e(this.TAG, `[${TFC[category]}] Un-caught terminal exception ${error.name} in retry-task`, ex);
return handleTerminalError(error);
} else {
HMSLogger.w(
this.TAG,
`[${TFC[category]}] Un-caught exception ${error.name} in retry-task, initiating retry`,
ex,
);
}
}

if (taskSucceeded) {
Expand Down

0 comments on commit 5999b07

Please sign in to comment.