Skip to content

Commit

Permalink
better retries
Browse files Browse the repository at this point in the history
  • Loading branch information
Equinox- committed Oct 9, 2024
1 parent 78073f8 commit 29e98af
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
10 changes: 6 additions & 4 deletions Meds.Watchdog/Steam/SteamDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Meds.Dist;
Expand All @@ -25,6 +26,7 @@ public static class SteamDownloaderFactory
{
public static void AddSteamDownloader(this IServiceCollection collection, SteamConfiguration config)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
var categoryCleaner = new Regex("^[0-9a-f]+/");
collection.AddSingleton(svc =>
{
Expand Down Expand Up @@ -154,7 +156,7 @@ private async Task<DepotManifest> GetManifestAsync(uint appId, uint depotId, ulo
CdnPool.ReturnServer(server);
return manifest;
}
catch (SteamKitWebRequestException)
catch
{
// ignore server errors + don't return it so the server isn't used again.
if (attempts++ > 5)
Expand Down Expand Up @@ -260,6 +262,9 @@ private async Task<InstallResult> InstallInternalAsync(uint appId, uint depotId,
string installPath, int workerCount, Predicate<string> installFilter, string debugName,
string branch, string installPrefix)
{
// Get installation details from Steam
var manifest = await GetManifestAsync(appId, depotId, manifestId, branch);

var localCache = new DistFileCache();
var localCacheFile = Path.Combine(installPath, DistFileCache.CacheDir, depotId.ToString());

Expand Down Expand Up @@ -301,9 +306,6 @@ private async Task<InstallResult> InstallInternalAsync(uint appId, uint depotId,
{
using (File.Create(lockFile))
{
// Get installation details from Steam
var manifest = await GetManifestAsync(appId, depotId, manifestId, branch);

var job = InstallJob.Upgrade(_log, appId, depotId, installPath, localCache, manifest, installFilter, result.InstalledFiles, installPrefix);
using (var timer = new Timer(3000) { AutoReset = true })
{
Expand Down
37 changes: 34 additions & 3 deletions Meds.Watchdog/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,15 @@ private Task LoginInternal()
var logoutTask = _loginLogoutTask;
_loginLogoutTask = Task.Run(async () =>
{
if (logoutTask != null) await logoutTask;
try
{
if (logoutTask != null) await logoutTask;
}
catch
{
// ignore errors from logout.
}
await _downloader.LoginAsync();
});
return _loginLogoutTask;
Expand All @@ -69,14 +77,37 @@ private Task LogoutInternal()
var loginTask = _loginLogoutTask;
_loginLogoutTask = Task.Run(async () =>
{
if (loginTask != null) await loginTask;
try
{
if (loginTask != null) await loginTask;
}
catch
{
// ignore errors from login.
}
await _downloader.LogoutAsync();
});
return _loginLogoutTask;
}
}

public ValueTask<LoginToken> Login() => LoginToken.Of(this);
public async ValueTask<LoginToken> Login()
{
var attempt = 0;
while (true)
{
try
{
return await LoginToken.Of(this);
}
catch
{
if (attempt++ < 5) continue;
throw;
}
}
}

public readonly struct LoginToken : IAsyncDisposable
{
Expand Down

0 comments on commit 29e98af

Please sign in to comment.