Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 47835d7

Browse files
committed
Added retries with delays.
#979 added a delay to the login process, but when porting that to the `fixes/809-refactor-logins` branch for #845 I discovered that a single 1s delay is sometimes not enough. Trying 3 times with a 1s delay however does seem to work.
1 parent 473d077 commit 47835d7

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/GitHub.Api/LoginManager.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,25 @@ public async Task<User> Login(
106106
} while (auth == null);
107107

108108
await loginCache.SaveLogin(userName, auth.Token, hostAddress).ConfigureAwait(false);
109-
return await client.User.Current().ConfigureAwait(false);
109+
110+
var retry = 0;
111+
112+
while (true)
113+
{
114+
try
115+
{
116+
return await client.User.Current().ConfigureAwait(false);
117+
}
118+
catch (AuthorizationException)
119+
{
120+
if (retry++ == 3) throw;
121+
}
122+
123+
// It seems that attempting to use a token immediately sometimes fails, retry a few
124+
// times with a delay of of 1s to allow the token to propagate.
125+
await Task.Delay(1000);
126+
System.Diagnostics.Debug.WriteLine("Retrying login " + retry);
127+
}
110128
}
111129

112130
/// <inheritdoc/>

0 commit comments

Comments
 (0)