Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retry when downloading clang tools #59806

Merged
merged 3 commits into from
Sep 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 10 additions & 24 deletions eng/formatting/download-tools.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
. "$PSScriptRoot/../common/tools.ps1" # for Retry function

function DownloadClangTool
{
function DownloadClangTool {
param (
[string]
$toolName,
Expand All @@ -10,28 +10,14 @@ function DownloadClangTool

$baseUri = "https://clrjit.blob.core.windows.net/clang-tools/windows"

if (-not $(ls $downloadOutputPath | Where-Object {$_.Name -eq "$toolName.exe"}))
{
$baseBackoffSeconds = 2;

$success = $false
for ($i = 0; $i -lt 5; $i++) {
echo "Attempting download of '$baseUri/$toolName.exe'"
$status = Invoke-WebRequest -Uri "$baseUri/$toolName.exe" -OutFile $(Join-Path $downloadOutputPath -ChildPath "$toolName.exe")
if ($status.StatusCode -lt 400)
{
$success = $true
break
} else {
echo "Download attempt $($i+1) failed. Trying again in $($baseBackoffSeconds + $baseBackoffSeconds * $i) seconds"
Start-Sleep -Seconds $($baseBackoffSeconds + $baseBackoffSeconds * $i)
}
}
if (-not $success)
{
Write-Output "Failed to download clang-format"
return 1
}
if (-not $(ls $downloadOutputPath | Where-Object { $_.Name -eq "$toolName.exe" })) {

Retry({
Write-Output "Downloading '$baseUri/$toolName.exe'"
# Pass -PassThru as otherwise Invoke-WebRequest leaves a corrupted file if the download fails. With -PassThru the download is buffered first.
# -UseBasicParsing is necessary for older PowerShells when Internet Explorer might not be installed/configured
$null = Invoke-WebRequest -Uri "$baseUri/$toolName.exe" -OutFile $(Join-Path $downloadOutputPath -ChildPath "$toolName.exe") -PassThru -UseBasicParsing
})
}
}

Expand Down