Retry server errors in dependency downloader (#4458)

This commit is contained in:
Alexander Shabalin
2020-10-22 13:28:43 +03:00
committed by GitHub
parent eb576258e3
commit cf9f9fe4bb
@@ -175,13 +175,7 @@ class DependencyDownloader(
var attempt = 1 var attempt = 1
var waitTime = 0L var waitTime = 0L
while (true) { val handleException = { e: Exception ->
try {
tryDownload(source, tmpFile)
break
} catch (e: HTTPResponseException) {
throw e
} catch (e: IOException) {
if (attempt >= maxAttempts) { if (attempt >= maxAttempts) {
throw e throw e
} }
@@ -192,6 +186,21 @@ class DependencyDownloader(
// TODO: Wait better // TODO: Wait better
Thread.sleep(waitTime) Thread.sleep(waitTime)
} }
while (true) {
try {
tryDownload(source, tmpFile)
break
} catch (e: HTTPResponseException) {
if (e.responseCode >= 500) {
// Retry server errors.
handleException(e)
} else {
// Do not retry client errors.
throw e
}
} catch (e: IOException) {
handleException(e)
}
} }
Files.move(tmpFile.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING) Files.move(tmpFile.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING)