From f5ed55827dc0b41fa254851f378961190bfe9f86 Mon Sep 17 00:00:00 2001 From: Colin Grogan Date: Sat, 15 Jul 2017 16:24:02 +0100 Subject: [PATCH 1/3] Try 3 times to download a package/metadata Packagesupplier.d now tries 3 times to download a package and metadata. This should aid travis to not be as flaky as it is currently. Implements enhancement request #1167 --- source/dub/packagesupplier.d | 45 ++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/source/dub/packagesupplier.d b/source/dub/packagesupplier.d index cf12f3c1bf..39d02492fb 100644 --- a/source/dub/packagesupplier.d +++ b/source/dub/packagesupplier.d @@ -185,13 +185,30 @@ class RegistryPackageSupplier : PackageSupplier { void fetchPackage(Path path, string packageId, Dependency dep, bool pre_release) { import std.array : replace; + import std.net.curl : CurlException; Json best = getBestPackage(packageId, dep, pre_release); if (best.type == Json.Type.null_) return; auto vers = best["version"].get!string; auto url = m_registryUrl ~ Path(PackagesPath~"/"~packageId~"/"~vers~".zip"); logDiagnostic("Downloading from '%s'", url); - download(url, path); + foreach(i; 0..3) { + try{ + download(url, path); + return; + } + catch(HTTPStatusException e) { + if (e.status == 404) { + logDebug("Failed to download package %s from %s (404)", packageId, url); + return; + } + else { + logDebug("Failed to download package %s from %s (Attempt %s of 3)", packageId, url, i + 1); + continue; + } + } + } + throw new Exception("Failed to download package %s from %s".format(packageId, url)); } Json fetchPackageRecipe(string packageId, Dependency dep, bool pre_release) @@ -214,14 +231,24 @@ class RegistryPackageSupplier : PackageSupplier { logDebug("Getting from %s", url); string jsonData; - try - jsonData = cast(string)download(url); - catch (HTTPStatusException e) - { - if (e.status != 404) - throw e; - logDebug("Package %s not found in %s: %s", packageId, description, e.msg); - return Json(null); + foreach(i; 0..3) { + try { + jsonData = cast(string)download(url); + break; + } + catch (HTTPStatusException e) + { + if (e.status == 404) { + logDebug("Package %s not found in %s (404): %s", packageId, description, e.msg); + return Json(null); + } + else { + logDebug("Package %s not found in %s (attempt %s of 3): %s", packageId, description, i + 1, e.msg); + if (i == 2) + throw e; + continue; + } + } } Json json = parseJsonString(jsonData, url.toString()); // strip readme data (to save size and time) From f6db3b35cd8eba5b4829656f195fb5897c702dd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Wed, 26 Jul 2017 11:48:58 +0200 Subject: [PATCH 2/3] Always throw for 404 errors. --- source/dub/packagesupplier.d | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/source/dub/packagesupplier.d b/source/dub/packagesupplier.d index 39d02492fb..3e7e35c25b 100644 --- a/source/dub/packagesupplier.d +++ b/source/dub/packagesupplier.d @@ -198,10 +198,7 @@ class RegistryPackageSupplier : PackageSupplier { return; } catch(HTTPStatusException e) { - if (e.status == 404) { - logDebug("Failed to download package %s from %s (404)", packageId, url); - return; - } + if (e.status == 404) throw e; else { logDebug("Failed to download package %s from %s (Attempt %s of 3)", packageId, url, i + 1); continue; @@ -239,11 +236,11 @@ class RegistryPackageSupplier : PackageSupplier { catch (HTTPStatusException e) { if (e.status == 404) { - logDebug("Package %s not found in %s (404): %s", packageId, description, e.msg); + logDebug("Package %s not found at %s (404): %s", packageId, description, e.msg); return Json(null); } else { - logDebug("Package %s not found in %s (attempt %s of 3): %s", packageId, description, i + 1, e.msg); + logDebug("Error getting metadata for package %s at %s (attempt %s of 3): %s", packageId, description, i + 1, e.msg); if (i == 2) throw e; continue; From e4859dd5b3baadf074ca52fa7efe2c90c74eb67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sat, 26 Aug 2017 12:39:54 +0200 Subject: [PATCH 3/3] Remove unused import. --- source/dub/packagesupplier.d | 1 - 1 file changed, 1 deletion(-) diff --git a/source/dub/packagesupplier.d b/source/dub/packagesupplier.d index 3e7e35c25b..061d28016b 100644 --- a/source/dub/packagesupplier.d +++ b/source/dub/packagesupplier.d @@ -185,7 +185,6 @@ class RegistryPackageSupplier : PackageSupplier { void fetchPackage(Path path, string packageId, Dependency dep, bool pre_release) { import std.array : replace; - import std.net.curl : CurlException; Json best = getBestPackage(packageId, dep, pre_release); if (best.type == Json.Type.null_) return;