From 310cebb0283f52e1431cd0aeb74c86d77b31a63c Mon Sep 17 00:00:00 2001 From: JohnMcPMS Date: Sun, 24 Sep 2023 10:06:01 -0700 Subject: [PATCH] Add a bit of randomness to the wait time after source update failure (#3661) --- 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