From 29e98afcd51afc7248683f91a817f0de995c2a00 Mon Sep 17 00:00:00 2001 From: Westin Miller Date: Wed, 9 Oct 2024 07:37:44 -0700 Subject: [PATCH] better retries --- Meds.Watchdog/Steam/SteamDownloader.cs | 10 ++++--- Meds.Watchdog/Updater.cs | 37 +++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/Meds.Watchdog/Steam/SteamDownloader.cs b/Meds.Watchdog/Steam/SteamDownloader.cs index 35f91cf..695c5af 100644 --- a/Meds.Watchdog/Steam/SteamDownloader.cs +++ b/Meds.Watchdog/Steam/SteamDownloader.cs @@ -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; @@ -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 => { @@ -154,7 +156,7 @@ private async Task 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) @@ -260,6 +262,9 @@ private async Task InstallInternalAsync(uint appId, uint depotId, string installPath, int workerCount, Predicate 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()); @@ -301,9 +306,6 @@ private async Task 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 }) { diff --git a/Meds.Watchdog/Updater.cs b/Meds.Watchdog/Updater.cs index 6c791bc..ac012d5 100644 --- a/Meds.Watchdog/Updater.cs +++ b/Meds.Watchdog/Updater.cs @@ -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; @@ -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 Login() => LoginToken.Of(this); + public async ValueTask Login() + { + var attempt = 0; + while (true) + { + try + { + return await LoginToken.Of(this); + } + catch + { + if (attempt++ < 5) continue; + throw; + } + } + } public readonly struct LoginToken : IAsyncDisposable {