Skip to content

Commit

Permalink
fix: Add retry logic in "_waitForPkamAuthSuccess" to retry when secon…
Browse files Browse the repository at this point in the history
…dary is temporarily not reachable
  • Loading branch information
sitaram-kalluri committed Oct 7, 2024
1 parent 208367a commit 502d708
Showing 1 changed file with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
AtSignLogger logger = AtSignLogger('OnboardingCli');
AtOnboardingPreference atOnboardingPreference;
AtLookUp? _atLookUp;
final _maxActivationRetries = 5;

/// The object which controls what types of AtClients, NotificationServices
/// and SyncServices get created when we call [AtClientManager.setCurrentAtSign].
Expand Down Expand Up @@ -321,15 +322,28 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
Duration retryInterval, {
bool logProgress = true,
}) async {
int retryAttempt = 1;
while (true) {
logger.info('Attempting pkam auth');
if (logProgress) {
stderr.write('Checking ... ');
}
bool pkamAuthSucceeded = await _attemptPkamAuth(
atLookUp,
enrollmentIdFromServer,
);
bool pkamAuthSucceeded = false;
try {
pkamAuthSucceeded =
await _attemptPkamAuth(atLookUp, enrollmentIdFromServer);
} catch (e) {
String message =
'Exception occurred when authenticating the atSign: $_atSign caused by ${e.toString()}';
if (retryAttempt > _maxActivationRetries) {
message += ' Activation failed after $_maxActivationRetries attempts';
logger.severe(message);
rethrow;
}
logger
.severe('$message. Attempting to retry for $retryAttempt attempt');
retryAttempt++;
}
if (pkamAuthSucceeded) {
if (logProgress) {
stderr.writeln(' approved.');
Expand Down Expand Up @@ -366,9 +380,6 @@ class AtOnboardingServiceImpl implements AtOnboardingService {
} else if (e.message.contains('error:AT0025')) {
throw AtEnrollmentException('enrollment denied');
}
} catch (e) {
logger.shout('Unexpected exception: $e');
rethrow;
} finally {
logger.finer('_attemptPkamAuth: complete');
}
Expand Down

0 comments on commit 502d708

Please sign in to comment.