From abb9d068e6860c57a07487b173c6b1c7d02e6560 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Fri, 2 Apr 2021 12:10:06 -0400 Subject: [PATCH] Retry 5 times As a workaround to "concurrent download" failure that happens frequently on an empty cache, this retries the resolution up to 5 times after 100ms wait. --- .../multiversion/commands/ExportCommand.scala | 5 +++-- .../configs/ThirdpartyConfig.scala | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/multiversion/src/main/scala/multiversion/commands/ExportCommand.scala b/multiversion/src/main/scala/multiversion/commands/ExportCommand.scala index 92752db..a9a84e9 100644 --- a/multiversion/src/main/scala/multiversion/commands/ExportCommand.scala +++ b/multiversion/src/main/scala/multiversion/commands/ExportCommand.scala @@ -55,7 +55,7 @@ case class ExportCommand( lintCommand: LintCommand = LintCommand(), @Description("Retry limit when fetching a file.") @ParseAsNumber - retryCount: Int = 2, + retryCount: Int = 5, @Description("Number of parallel resolves and downloads.") @ParseAsNumber parallel: Int = 4, @@ -401,7 +401,8 @@ case class ExportCommand( dep, cache, progressBar, - cdep + cdep, + retryCount ) for { diff --git a/multiversion/src/main/scala/multiversion/configs/ThirdpartyConfig.scala b/multiversion/src/main/scala/multiversion/configs/ThirdpartyConfig.scala index 3f04e8f..29b3ae2 100644 --- a/multiversion/src/main/scala/multiversion/configs/ThirdpartyConfig.scala +++ b/multiversion/src/main/scala/multiversion/configs/ThirdpartyConfig.scala @@ -10,6 +10,7 @@ import coursier.cache.FileCache import coursier.core.Dependency import coursier.core.Module import coursier.core.Reconciliation +import coursier.core.Resolution import coursier.params.ResolutionParams import coursier.util.ModuleMatchers import coursier.util.Task @@ -98,7 +99,8 @@ final case class ThirdpartyConfig( dep: DependencyConfig, cache: FileCache[Task], progressBar: ResolveProgressRenderer, - cdep: Dependency + cdep: Dependency, + retryCount: Int ): Result[Task[Result[DependencyResolution]]] = Result.fromResults(decodeForceVersions(dep)).map { decodedForceVersions => val allDependencies = for { @@ -116,7 +118,20 @@ final case class ThirdpartyConfig( .withRepositories( if (repos.isEmpty) Resolve.defaultRepositories else repos ) - resolve.io.map(r => DependencyResolution(dep, r)).toResult + + def retry(m: Int) = + Task.tailRecM[Int, Resolution](m) { (n: Int) => + if (n <= 0) resolve.io.map(Right(_)) + else + resolve.io.attempt map { + case Right(r) => Right(r) + case Left(e) if e.getMessage.contains("concurrent download") => + Thread.sleep(100) + Left(n - 1) + case Left(e) => throw e + } + } + retry(retryCount).map(r => DependencyResolution(dep, r)).toResult } private type ForceVersionResult =