From dc306c5489c2f5f294ae076edd7571c985e81143 Mon Sep 17 00:00:00 2001 From: Patrick Hallisey Date: Tue, 21 May 2024 09:37:31 -0700 Subject: [PATCH] Stop retrying on 404s --- .../Utils/FileHelpers.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/FileHelpers.cs b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/FileHelpers.cs index 5109598f437..dfd7ba2feba 100644 --- a/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/FileHelpers.cs +++ b/tools/codeowners-utils/Azure.Sdk.Tools.CodeownersUtils/Utils/FileHelpers.cs @@ -57,9 +57,10 @@ private static string GetUrlContents(string url) using HttpClient client = new HttpClient(); while (attempts <= maxRetries) { + HttpResponseMessage response = null; try { - HttpResponseMessage response = client.GetAsync(url).ConfigureAwait(false).GetAwaiter().GetResult(); + response = client.GetAsync(url).ConfigureAwait(false).GetAwaiter().GetResult(); if (response.StatusCode == HttpStatusCode.OK) { // This writeline is probably unnecessary but good to have if there are previous attempts that failed @@ -76,13 +77,19 @@ private static string GetUrlContents(string url) // HttpRequestException means the request failed due to an underlying issue such as network connectivity, // DNS failure, server certificate validation or timeout. Console.WriteLine($"GetUrlContents attempt number {attempts}. HttpRequestException trying to fetch {url}. Exception message = {httpReqEx.Message}"); - if (attempts == maxRetries) - { - // At this point the retries have been exhausted, let this rethrow - throw; - } + + } + + // Skip retries on a NotFound response + if (response?.StatusCode == HttpStatusCode.NotFound) + { + return null; + } + + if (attempts < maxRetries) + { + System.Threading.Thread.Sleep(delayTimeInMs); } - System.Threading.Thread.Sleep(delayTimeInMs); attempts++; } // This will only get hit if the final retry is non-OK status code