From 887e120689839e4e56f278a49d221808d0fe8a07 Mon Sep 17 00:00:00 2001 From: JohnMcPMS Date: Sat, 23 Sep 2023 18:18:55 -0700 Subject: [PATCH] Add a bit of randomness to the wait time after source update failure --- src/AppInstallerRepositoryCore/RepositorySource.cpp | 7 ++++++- src/AppInstallerRepositoryCore/pch.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/AppInstallerRepositoryCore/RepositorySource.cpp b/src/AppInstallerRepositoryCore/RepositorySource.cpp index b3522a763b..156c38f1fe 100644 --- a/src/AppInstallerRepositoryCore/RepositorySource.cpp +++ b/src/AppInstallerRepositoryCore/RepositorySource.cpp @@ -53,7 +53,12 @@ namespace AppInstaller::Repository CATCH_LOG(); AICLI_LOG(Repo, Info, << "Source add/update failed, waiting a bit and retrying: " << details.Name); - std::this_thread::sleep_for(2s); + + // Add a bit of randomness to the retry wait time + std::default_random_engine randomEngine(std::random_device{}()); + std::uniform_int_distribution distribution(2000, 10000); + + std::this_thread::sleep_for(std::chrono::milliseconds(distribution(randomEngine))); // If this one fails, maybe the problem is persistent. result = (factory.get()->*member)(details, progress); diff --git a/src/AppInstallerRepositoryCore/pch.h b/src/AppInstallerRepositoryCore/pch.h index 09c622c1b2..df1d971c19 100644 --- a/src/AppInstallerRepositoryCore/pch.h +++ b/src/AppInstallerRepositoryCore/pch.h @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include