Skip to content

Commit d34e60a

Browse files
author
Anton Tayanovskyy
committed
Make download loop to terminate in max N=5 iterations
1 parent 490cccc commit d34e60a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

‎src/Paket.Core/NuGetV2.fs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ let DownloadPackage(root, (source : PackageSource), caches:Cache list, groupName
892892
| _ -> getFromCache rest
893893
| [] -> false
894894

895-
let rec download authenticated =
895+
let rec download authenticated attempt =
896896
async {
897897
if not force && targetFile.Exists && targetFile.Length > 0L then
898898
verbosefn "%O %O already downloaded." packageName version
@@ -979,16 +979,17 @@ let DownloadPackage(root, (source : PackageSource), caches:Cache list, groupName
979979
traceWarnfn "Could not download license for %O %O from %s.%s %s" packageName version nugetPackage.LicenseUrl Environment.NewLine exn.Message
980980
with
981981
| :? System.Net.WebException as exn when
982+
attempt < 5 &&
982983
exn.Status = WebExceptionStatus.ProtocolError &&
983984
(match source.Auth |> Option.map toBasicAuth with
984985
| Some(Credentials(_)) -> true
985986
| _ -> false)
986-
-> do! download false
987+
-> do! download false (attempt + 1)
987988
| exn when String.IsNullOrWhiteSpace !downloadUrl -> failwithf "Could not download %O %O.%s %s" packageName version Environment.NewLine exn.Message
988989
| exn -> failwithf "Could not download %O %O from %s.%s %s" packageName version !downloadUrl Environment.NewLine exn.Message }
989990

990991
async {
991-
do! download true
992+
do! download true 0
992993
let! files = CopyFromCache(root, groupName, targetFile.FullName, licenseFileName, packageName, version, includeVersionInPath, force, detailed)
993994
return targetFileName,files
994995
}

0 commit comments

Comments
 (0)