Skip to content

Commit

Permalink
[APT-10467] Retry with Exponential Backoff
Browse files Browse the repository at this point in the history
Adds graceful network retries to internet connectivity errors.

And attempts to retry `ParserException`, in the event that the download partially failed for content being loaded over the internet.
  • Loading branch information
kabliz committed Sep 20, 2024
1 parent 295a2ef commit debf27a
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ class ArmadilloHttpErrorHandlingPolicy : DefaultLoadErrorHandlingPolicy(DEFAULT_
override fun getRetryDelayMsFor(loadErrorInfo: LoadErrorHandlingPolicy.LoadErrorInfo): Long {
return if (loadErrorInfo.exception is UnknownHostException || loadErrorInfo.exception is SocketTimeoutException) {
//retry every 10 seconds for potential loss of internet -keep buffering - internet may later succeed.
if (loadErrorInfo.errorCount > 8) {
C.TIME_UNSET //stop retrying after a few minutes
if (loadErrorInfo.errorCount > 6) {
C.TIME_UNSET //stop retrying after around 10 minutes
} else {
//exponential backoff based on a 10 second interval
(1 shl (loadErrorInfo.errorCount - 1).coerceAtMost(8)) * 10 * 1000L
(1 shl (loadErrorInfo.errorCount - 1).coerceAtMost(6)) * 10 * 1000L
}
} else if (loadErrorInfo.exception is ParserException) {
/*
Exoplayer by default assumes ParserExceptions only occur because source content is malformed,
so Exoplayer will never retry ParserExceptions.
We care about content failing to checksum correctly over the internet, so we wish to retry these.
*/
if (loadErrorInfo.errorCount > 4) {
if (loadErrorInfo.errorCount > 3) {
C.TIME_UNSET //stop retrying, the content is likely malformed
} else {
//This is exponential backoff based on a 1 second interval
(1 shl (loadErrorInfo.errorCount - 1).coerceAtMost(4)) * 1000L
(1 shl (loadErrorInfo.errorCount - 1).coerceAtMost(3)) * 1000L
}
} else {
super.getRetryDelayMsFor(loadErrorInfo)
Expand Down

0 comments on commit debf27a

Please sign in to comment.