Retry server errors in dependency downloader (#4458)
This commit is contained in:
committed by
GitHub
parent
eb576258e3
commit
cf9f9fe4bb
@@ -175,22 +175,31 @@ class DependencyDownloader(
|
|||||||
|
|
||||||
var attempt = 1
|
var attempt = 1
|
||||||
var waitTime = 0L
|
var waitTime = 0L
|
||||||
|
val handleException = { e: Exception ->
|
||||||
|
if (attempt >= maxAttempts) {
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
attempt++
|
||||||
|
waitTime += attemptIntervalMs
|
||||||
|
println("Cannot download a dependency: $e\n" +
|
||||||
|
"Waiting ${waitTime.toDouble() / 1000} sec and trying again (attempt: $attempt/$maxAttempts).")
|
||||||
|
// TODO: Wait better
|
||||||
|
Thread.sleep(waitTime)
|
||||||
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
tryDownload(source, tmpFile)
|
tryDownload(source, tmpFile)
|
||||||
break
|
break
|
||||||
} catch (e: HTTPResponseException) {
|
} catch (e: HTTPResponseException) {
|
||||||
throw e
|
if (e.responseCode >= 500) {
|
||||||
} catch (e: IOException) {
|
// Retry server errors.
|
||||||
if (attempt >= maxAttempts) {
|
handleException(e)
|
||||||
|
} else {
|
||||||
|
// Do not retry client errors.
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
attempt++
|
} catch (e: IOException) {
|
||||||
waitTime += attemptIntervalMs
|
handleException(e)
|
||||||
println("Cannot download a dependency: $e\n" +
|
|
||||||
"Waiting ${waitTime.toDouble() / 1000} sec and trying again (attempt: $attempt/$maxAttempts).")
|
|
||||||
// TODO: Wait better
|
|
||||||
Thread.sleep(waitTime)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user