diff --git a/src/Microsoft.Deployment.DotNet.Releases/src/Utils.cs b/src/Microsoft.Deployment.DotNet.Releases/src/Utils.cs index 88076ab524..63b4900387 100644 --- a/src/Microsoft.Deployment.DotNet.Releases/src/Utils.cs +++ b/src/Microsoft.Deployment.DotNet.Releases/src/Utils.cs @@ -28,7 +28,7 @@ internal class Utils internal static async Task IsLatestFileAsync(string fileName, Uri address) { var httpRequest = new HttpRequestMessage(HttpMethod.Head, address); - HttpResponseMessage httpResponse = await s_httpClient.SendAsync(httpRequest).ConfigureAwait(false); + using HttpResponseMessage httpResponse = await s_httpClient.SendAsync(httpRequest).ConfigureAwait(false); httpResponse.EnsureSuccessStatusCode(); @@ -61,7 +61,7 @@ internal static async Task DownloadFileAsync(Uri address, string fileName) } else { - HttpResponseMessage httpResponse = await s_httpClient.GetAsync(address).ConfigureAwait(false); + using HttpResponseMessage httpResponse = await s_httpClient.GetAsync(address).ConfigureAwait(false); httpResponse.EnsureSuccessStatusCode(); using FileStream stream = File.Create(fileName); @@ -149,7 +149,7 @@ internal static async Task GetLatestFileAsync(string path, bool downloadLatest, static Utils() { - s_httpClient = new HttpClient(); + s_httpClient = new HttpClient(new HttpClientHandler(), disposeHandler: true); s_httpClient.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true